加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dojo事件绑定

发布时间:2020-12-16 21:32:59 所属栏目:百科 来源:网络整理
导读: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 id="span1"span1

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"),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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读