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")'>

我尝试了退货,因为这是我在另一个答案中找到的,但它仍然不起作用。我将不胜感激任何帮助谢谢!

4

1 回答 1

1

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

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

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

在函数中使用事件对象:

function bimageswap(event, step) {
  event.stopPropagation();
  ...
于 2011-08-05T06:30:21.560 回答