从onclick属性调用e.stopImmediatePropagation() [英] calling e.stopImmediatePropagation() from onclick attribute
本文介绍了从onclick属性调用e.stopImmediatePropagation()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 onclick
属性获取事件对象?
How do I get the event object from an onclick
attribute?
我试过了:
<a href="something.html" onclick="function(e){e.stopImmediatePropagation();}">Click me</a>
另外,我试过这个:
Also, I have tried this:
<a href="something.html" onclick="console.log(this);">Click me</a>
但控制台只显示< a>
元素。
推荐答案
我想你必须在<脚本中定义函数/ b>
标签在其他地方。
I think you'd have to define the function in a <script/>
tag elsewhere.
b
<script type="text/javascript">
$('#something_link').click(function(e) {
e.stopImmediatePropagation();
});
</script>
<a href="something.html" id="something_link">Click me</a>
这篇关于从onclick属性调用e.stopImmediatePropagation()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文