有了webcomponents,您可以使用/deep/来定位阴影的内部元素,在我尝试使用事件委托之前,它工作得很好。
常规的点击功能将起作用:
$('html /deep/ a').on('click', function(e) {
e.preventDefault()
console.log('foo')
})委派似乎没有效果:
$('html').on('click', '/deep/ a', function(e) {
e.preventDefault()
console.log('bar')
})你知道该怎么做吗?
发布于 2015-01-13 06:59:30
阴影DOM重定事件的目标,使它们看起来像来自主体元素。这是为了保留封装模型(否则您可能会抓取目标并在组件中胡乱操作)。
http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-301/#toc-events
也许您可以尝试委托宿主元素,然后使用event.path来确定是否单击了某个a?
https://stackoverflow.com/questions/27693538
复制相似问题