Closed litson closed 9 years ago
在移动浏览器当中, 使用delegate(或on、live), 绑定在$wrapper(指父级元素), 有的时候会冒泡不上去,特别是层级复杂、伴有定位的时候
// 举个简单的例子; // 但这个例子并不会发生上述问题,怪我比较罗嗦; <body> <div id='view'> <a href='javascript:;' data-action='nothingToDo'>btn</a> </div> </body>
// 直接绑定在body上,无效 $(document.body).on('click', '[data-action]' , function(){ console.log(this) ; }); // 绑定在较近的父级元素上,有效 $('#view').on('click', '[data-action]' , function(){ console.log(this) ; });
请问这个有没有比较好的解决方案;
我想我知道你描述问题是什么,请稍等,我会写篇文档来解答这个问题。
我猜测你遇到的情况跟层级和定位没有直接关系,跟目标元素的类型有关系。
详见这篇文档: #23。
在移动浏览器当中, 使用delegate(或on、live), 绑定在$wrapper(指父级元素), 有的时候会冒泡不上去,特别是层级复杂、伴有定位的时候
请问这个有没有比较好的解决方案;