我有一个HTML DIV我的JSP页面上,对我已经把一个锚标记,请在下方找到代码是,HTML DIV onclick事件
<div class="expandable-panel-heading">
<h2>
<a id="ancherComplaint" href="#addComplaint"
onclick="markActiveLink(this);">ABC</a>
</h2>
</div>
js代码
$('.expandable-panel-heading:not(#ancherComplaint)').click(function() {
alert('123');
});
function markActiveLink(el) {
alert($(el).attr("id"));
}
这里我当我点击div我得到了123
消息的警报,但它很好,但当我点击ABC我想要调用markActiveLink
方法的消息。
什么是错我的代码?请帮助我。
您需要在事件读了冒泡和肯定删除内联事件处理,如果你有jQuery – mplungjan
可能重复[jQuery stopPropagation bubble down](http:// stackoverflow .com/questions/2728252/jquery-stoppropagation-bubble-down) –
您可以继续使用这个,只需要在使用onclick之前放置该方法即可。在此处更新提琴http://jsfiddle.net/JVrNc/7/ – vipulsharma