Javascript:stopPropagation 仅在第一次有效?

发布于 2024-11-27 08:03:46 字数 444 浏览 1 评论 0原文

我的按钮仅在第一次被单击时被“单击”。此后每次,单击事件都会立即传播到父级的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木落 2024-12-04 08:03:46

如果 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 the e.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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文