zoukankan      html  css  js  c++  java
  • dojo事件绑定

    Dojo如何动态绑定事件的小demo

     1 <html>  
     2 <title>事件绑定测试test</title>  
     3 <head></head>  
     4 <style>  
     5 .reds{  
     6 color:red;  
     7 }  
     8   
     9 .sizes{  
    10 font-size:30px;  
    11 }  
    12 </style>  
    13 <script type="text/javascript" src="../dojo/dojo/dojo.js" djConfig="parseOnLoad: true"></script>  
    14   
    15 <body>  
    16 <div>  
    17     <span id="span1">span1</span>  
    18     <span id="span2">span2</span>  
    19 </div>  
    20   
    21 <input type="button" value="test_bind_function" id="bind_test"><br>  
    22 <button onclick="bind()">绑定事件</button><br>  
    23 <button onclick="unbind()">取消绑定</button><br>  
    24   
    25 </body>  
    26 </html>  
    27   
    28 <script>  
    29 function test(){  
    30     dojo.query("span").map(function(item,index){  
    31         //alert(item.innerHTML);  
    32         dojo.connect(item,"onclick",function(){  
    33             alert(item.innerHTML);  
    34         });  
    35     });   
    36 }  
    37   
    38 var handle;  
    39   
    40 function bind(){  
    41     handle = dojo.connect(dojo.byId("bind_test"),"onclick",function(){  
    42         alert("绑定成功");  
    43     });  
    44 }  
    45   
    46 function unbind(){  
    47     dojo.disconnect(handle);  
    48 }  
    49   
    50 //dojo检测不同的浏览器的方法  
    51 if(dojo.isIE){  
    52     alert("dojo.isIE");  
    53 }else{  
    54     alert("is not explorer");  
    55 }  
    56   
    57 function init(){  
    58     test();  
    59 }  
    60   
    61 //相当于onload方法,在页面代码执行完之后执行这个方法,函数里面必须包含方法,否则会报错误  
    62 dojo.addOnLoad(init);//这个方法与dojo.ready(function(){});功能是一样的  
    63 </script>
  • 相关阅读:
    fzu 2122
    hdu 4707 bellman
    sicily 10330. Cutting Sausages
    湖南省2016省赛题。1809: Parenthesis 线段树
    Panoramic Photography
    B. No Time for Dragons 贪心
    The Weakest Sith
    E. The Best among Equals
    Gym 101149I I
    AtCoder D
  • 原文地址:https://www.cnblogs.com/xiaocai0923/p/7600186.html
Copyright © 2011-2022 走看看