我有一个父锚链接与许多子跨度元素。当用户点击跨度时,我执行不同的操作。jquery点击检测目标孩子
此刻我简单地关闭默认点击行为,然后绑定我的自定义点击。 如何将它合并为一个点击功能?或者是正确的处理方式?
<a href='http://www.test.com' target='_blank'><span>Link</span> other non clickable text</a>
// Bind menu items
$('a').each(function() {
var $item = $(this);
// Turn off default click
$item.click(function(){
return false;
});
// Click label text
$item.children('span').eq(0).click(function(e){
e.preventDefault();
e.stopPropagation();
if($item.attr("href")) {
//window.location = '//' + $item.attr("href");
alert('window.location');
}
});
}); // each
http://jsbin.com/oFeMIPI/2/?html,js,output