stopPropagation onclick 在嵌套列表中不起作用

发布于 2024-11-27 22:43:59 字数 663 浏览 2 评论 0原文

我有以下功能,可以在嵌套列表中单击 ul 时交换图像,但它不会停止冒泡列表..

function bimageswap (step) {
    step.stopPropagation;
    realstep = parseInt(step) + 1;
    nextsteps = realstep + 1;
    for (iss = nextsteps;iss <= 5; iss++) {
        document.getElementById("step" + iss).className = 'step' + iss;
        alert(iss);
    }
    document.getElementById("step" + realstep).className = 'step' + realstep + 'a';
/*$("#step2").css( 'background-image', 'images/adtl_prodimg/discs/step1_.png');*/
    return false;
}

它是这样调用的:

<ul onclick='return bimageswap("4")'>

我尝试了返回,因为这是我在另一个答案中找到的,但它还是不行。我将非常感谢任何帮助,谢谢!

i have the following function to swap images on the click of a ul in a nested list, but it doesnt stop bubbling up the list..

function bimageswap (step) {
    step.stopPropagation;
    realstep = parseInt(step) + 1;
    nextsteps = realstep + 1;
    for (iss = nextsteps;iss <= 5; iss++) {
        document.getElementById("step" + iss).className = 'step' + iss;
        alert(iss);
    }
    document.getElementById("step" + realstep).className = 'step' + realstep + 'a';
/*$("#step2").css( 'background-image', 'images/adtl_prodimg/discs/step1_.png');*/
    return false;
}

it is called like this:

<ul onclick='return bimageswap("4")'>

i tried the return because it is what i found in another answer but it still doesnt work. i would greatly appreciate any help thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

素衣风尘叹 2024-12-04 22:43:59

stopPropagation 方法位于 event 对象中,您不能在字符串上调用它。您还缺少括号,因此它只会从字符串中获取 stopPropagation 属性(返回 undefined)并丢弃它。

将事件对象从事件处理程序发送到函数:

<ul onclick="bimageswap(event, '4');">

在函数中使用事件对象:

function bimageswap(event, step) {
  event.stopPropagation();
  ...

The stopPropagation method is in the event object, you can't call it on a string. You are also missing the parentheses, so it would just get the stopPropagation property from the string (which returns undefined) and discard it.

Send the event object from the event handler to the function:

<ul onclick="bimageswap(event, '4');">

Use the event object in the function:

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