Javascript:stopPropagation 仅在第一次有效?
我的按钮仅在第一次被单击时被“单击”。此后每次,单击事件都会立即传播到父级的 onclick。这是按钮的 onclick:
$('.clickable .moveUp').click(function(e) {
moveUpWorkoutExercise($(this));
e.stopPropagation();
});
和 HTML 概要:
<div class="clickable" onclick="toggleExerciseDetails(311,false)">
<a class="moveUp disabled" title="Move this exercise up"></a>
如何使该事件每次都有效,而不仅仅是第一次?谢谢!
My button is only being 'clicked' the first time it is clicked. Every time after, the click event is immediately propagated to the parent's onclick. Here is the button's onclick:
$('.clickable .moveUp').click(function(e) {
moveUpWorkoutExercise($(this));
e.stopPropagation();
});
And the HTML outline:
<div class="clickable" onclick="toggleExerciseDetails(311,false)">
<a class="moveUp disabled" title="Move this exercise up"></a>
How can I make the event work every time and not just the first time? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
moveUpWorkoutExercise()
函数中发生错误,则事件处理程序的执行将在到达e.stopPropagation();
行之前停止。该函数中是否有某些内容可能会因第二次和后续点击而中断?(您可以尝试首先放置
e.stopPropogation()
并看看会发生什么,但假设如果这确实“有效”,它并没有真正解决根本问题。)If an error occurs within the
moveUpWorkoutExercise()
function then execution of your event handler will stop before it gets to thee.stopPropagation();
line. Is there something in that function that might break for second and subsequent clicks?(You could try putting
e.stopPropogation()
first and see what happens, but hypothetically if that does "work" it hasn't really fixed the underlying problem.)