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 οnclick="bind()">绑定事件</button><br>  
23 <button οnclick="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>

转载于:https://www.cnblogs.com/xiaocai0923/p/7600186.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值