Dojo如何动态绑定事件的小demo htmltitle事件绑定测试test/titlehead/headstyle.reds{color:red;}.sizes{font-size:30px;}/stylescript type="text/javascript" src="../dojo/dojo/dojo.js" djConfig="parseOnLoad: true"/scriptbodydivspan
Dojo如何动态绑定事件的小demo
<html> <title>事件绑定测试test</title> <head></head> <style> .reds{ color:red; } .sizes{ font-size:30px; } </style> <script type="text/javascript" src="../dojo/dojo/dojo.js" djConfig="parseOnLoad: true"></script> <body> <div> <span id="span1">span1</span> <span id="span2">span2</span> </div> <input type="button" value="test_bind_function" id="bind_test"><br> <button onclick="bind()">绑定事件</button><br> <button onclick="unbind()">取消绑定</button><br> </body> </html> <script> function test(){ dojo.query("span").map(function(item,index){ //alert(item.innerHTML); dojo.connect(item,"onclick",function(){ alert(item.innerHTML); }); }); } var handle; function bind(){ handle = dojo.connect(dojo.byId("bind_test"),"onclick",function(){ alert("绑定成功"); }); } function unbind(){ dojo.disconnect(handle); } //dojo检测不同的浏览器的方法 if(dojo.isIE){ alert("dojo.isIE"); }else{ alert("is not explorer"); } function init(){ test(); } //相当于onload方法,在页面代码执行完之后执行这个方法,函数里面必须包含方法,否则会报错误 dojo.addOnLoad(init);//这个方法与dojo.ready(function(){});功能是一样的 </script>