stopPropagation onclick 在嵌套列表中不起作用
我有以下功能,可以在嵌套列表中单击 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
stopPropagation
方法位于event
对象中,您不能在字符串上调用它。您还缺少括号,因此它只会从字符串中获取stopPropagation
属性(返回undefined
)并丢弃它。将事件对象从事件处理程序发送到函数:
在函数中使用事件对象:
The
stopPropagation
method is in theevent
object, you can't call it on a string. You are also missing the parentheses, so it would just get thestopPropagation
property from the string (which returnsundefined
) and discard it.Send the event object from the event handler to the function:
Use the event object in the function: