停止传播不起作用。 [英] Stoppropagation not working.

查看:59
本文介绍了停止传播不起作用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在锚中有一个图像。现在通过单击TAB我关注锚点并按下ENTER。实际操作是在图像的onclick中写入的。所以,在onclick of anchor我正在调用图像onclick方法来执行。但是在执行锚标记之后,onclick再次被称为传播,并且无限循环正在开始。



任何人都可以帮我解决问题。



完整代码在这里。



Hi,

I have an image within an anchor. Now by clicking TAB I am focusing on the anchor and hitting ENTER. The actual operation is written within the onclick of the image. So, on the onclick of anchor I am calling the image onclick method to perform. But after performing the anchor tag onclick is being called again as propagation, and an infinite loop is getting started.

Can any one please help me to get a solution.

Full code is here.

<a onclick="alert('a clicked'); $('#i').click();" href="#" style="padding:60px 60px 60px 60px;">
<img src="Desert.jpg" width="50px" height="50x" id="i" onclick="alert('img clicked'); window.event.cancelBubble = true;event.stopPropagation();" />
</a>





我的尝试:



为了解决这个问题,我使用了

window.event.cancelBubble = true;

event.stopPropagation ();



但它不起作用。



注意:首先点击图片,stopPropagation是工作但点击锚点首先导致无限循环。



What I have tried:

To solve this I have used
window.event.cancelBubble = true;
event.stopPropagation();

But its not working.

Note: Clicking on the image first, stopPropagation is working but clicking on the anchor first leads to an infinite loop.

推荐答案

('#i')。click(); href = style = 填充:60px 60px 60px 60px; >
< img src = Desert.jpg width = 50px height = 50x id = i onclick = alert('img clicked'); window.event.cancelBubble = true; event.stopPropagation(); / >
< / a >
('#i').click();" href="#" style="padding:60px 60px 60px 60px;"> <img src="Desert.jpg" width="50px" height="50x" id="i" onclick="alert('img clicked'); window.event.cancelBubble = true;event.stopPropagation();" /> </a>





我的尝试:



为了解决这个问题,我使用了

window.event.cancelBubble = true;

event.stopPropagation ();



但它不起作用。



注意:首先点击图片,stopPropagation是工作但点击锚点首先导致无限循环。



What I have tried:

To solve this I have used
window.event.cancelBubble = true;
event.stopPropagation();

But its not working.

Note: Clicking on the image first, stopPropagation is working but clicking on the anchor first leads to an infinite loop.


在你的所有函数添加返回false之后,或者从上一个函数返回false;它将停止



After all your function add return false, or from last function return false; It will stop

onclick="alert('img clicked'); return false;"





javascript - event.preventDefault()与return false - Stack Overflow [ ^ ]


这篇关于停止传播不起作用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆