脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-一天一个js(7)研究jquery的委托事件,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
<!DOCTYPE HTML>
<htML><head>
<meta http-equiv="Content-type" content="text/html; charset=gb2312">
<tITle>事件委托</title>
<script src="https://ajax.GOOGLEapis.COM/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
VAR i = 1;
$(".add").click(function(){
i++;
var li = $(".all li:First").clone().children("input").attr("class","BTn"+i).siblings("em").text(i).parent();
$(".all ul").append(li);
});
$(".btn2").bind("click",function(){
$(this).next().show();
});
$(".btn3").live("click",function(){
$(this).next().show();
});
$(".all").delegate(".btn5","click",function(){
$(this).next().show();
});
$(".btn6").on("click",function(){
$(this).next().show();
});
$(".all").on("click",".btn7",function(){
$(this).next().show();
});
});
(function($){
$(".all .btn4").live("click",function(){
$(this).next().show();
});
})(jQuery);
</script>
<style>
.all { width:800px; margin:50px auto;}
.all ul { padding:20px; border:1px solid #000; list-style:none;}
.all li { margin:0 0 10px; width:200px; height:24px; overflow:auto; zoom:1; list-style:none;}
.all li input { float:left;}
.all li span { display:none; float:left; margin:0 0 0 5px; font:12px/24px "microsoft yahei"; color:#069;}
.all li em { float:left; margin:0 10px 0 0; font:12px/24px "microsoft yahei"; color:#c00;}
</style>
</head>
<body>
<p class="all">
<input type="button" class="add" value="增加一个东东" />
<p>第一个无效果,第二个bind,第三个live,第四个live的早委托,第五个delegate,第六个on的bind效果,第七个是on的live效果</p>
<ul>
<li><em>1</em><input type="button" value="点我啊!" class="btn1" /><span>你点了按钮</span></li>
</ul>
</p>
</body>
</html>
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-一天一个js(7)研究jquery的委托事件全部内容,希望文章能够帮你解决javascript代码实例教程-一天一个js(7)研究jquery的委托事件所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。