on事件绑定阻止冒泡的问题
2016-12-30 11:29
417 查看
当使用on进行事件绑定时当要给document绑定click,而子元素要禁止冒泡,那么子元素里面的子元素的click事件就会无效了,
下面无效版:
参考http://www.cnblogs.com/tengj/p/4794947.html对其进行了理解
暂时没空后面补理解
下面无效版:
$('#queue').on('click', '.link', function() { var t = $(this) ,box = t.next() if(t.hasClass('active')) { box.hide() t.removeClass('active') } else { box.show() t.addClass('active') } event.stopPropagation() }) //排队列表收缩 $(document).on('click','body',function(){ $('.link').removeClass('active') $('.queue-box').hide(); }) $('#queue').on('click','.queue-box',function(){//绑 $('#queue')或 $(document)都一样 event.stopPropagation() //主要是下面 $(document).on('click','.btn-queue-join',function(){ mywebsocket.send(JSON.stringify({ "action": "patientJoinQueue", "patientCode": patientCode, "orderCode": $(this).parents('.item').attr('data-id') })) });
//修改$(document)为$('.queue-box')就可以了 $('.queue-box').on('click','.btn-queue-join',function(){ mywebsocket.send(JSON.stringify({ "action": "patientJoinQueue", "patientCode": patientCode, "orderCode": $(this).parents('.item').attr('data-id') })) });
参考http://www.cnblogs.com/tengj/p/4794947.html对其进行了理解
暂时没空后面补理解
相关文章推荐
- jquery使用on()方法绑定元素阻止事件冒泡问题
- 解决VUE框架 导致绑定事件的阻止冒泡失效问题
- JQuery阻止冒泡事件on绑定中异常情况分析
- 关于jquery中用on绑定事件后的事件冒泡问题
- jquery中on动态绑定阻止冒泡事件异常
- jQuery中on绑定事件后引发的事件冒泡问题如何解决
- JQUERY中的事件处理:RETURN FALSE、阻止默认行为、阻止冒泡以及兼容性问题
- jQuery中的事件处理:return false、阻止默认行为、阻止冒泡以及兼容性问题
- 阻止ie、chrome中的事件冒泡和监听函数的覆盖问题
- iOS上的jQuery.on()冒泡事件绑定 给body添加点击事件
- jQuery使用on()绑定动态生成元素的事件无效的问题
- iOS上的jQuery.on()冒泡事件绑定 以及 iOS绝对定位元素中的输入框
- 冒泡,setinterval,背景图的div绑定事件,匿名函数问题--工作中的思考
- JavaScript 事件流(事件要素/普通事件/事件绑定/事件冒泡/阻止冒泡/阻止默认行为)
- jQuery使用on()绑定动态生成元素的事件无效的问题
- JQUERY中的事件处理:RETURN FALSE、阻止默认行为、阻止冒泡以及兼容性问题
- js验证阻止表单提交(表单绑定onsubmit事件)
- dojo中的on绑定事件问题
- on绑定阻止冒泡失败
- iOS使用on绑定click事件出现绑定父标签闪烁的问题