为什么这个内联停止传播方法调用不起作用?



我有这个按钮:

<button 
type="button" 
onclick='parent.parent.ExecuteCommand(14);event.stopPropagation()' 
class="button_air-medium">
<img 
id="selectMode" 
class="shortcutContant" 
src="../stdicons/icon_select.gif">
</button>

正如您在 onclick 属性中看到的那样,我调用了 2 个函数ExecuteCommandstopPropagation

执行命令工作正常,但在我看来stopPropagation方法没有触发,因为按钮下的元素受到影响。

知道为什么停止传播方法不起作用吗?

您可能没有可用于您正在使用的浏览器中的内联处理程序的event

如果你这样做,你会有一个更轻松的时间

$(function() { 
$(".button_air-medium").on("click",function(e) { 
e.stopPropagation(); 
parent.parent.ExecuteCommand($(this).data("commandnumber")) 
// or return false here
});
});

<button type="button" data-commandnumber="14"
class="button_air-medium"><img id="selectMode" class="shortcutContant" 
src="../stdicons/icon_select.gif"></button>

如果要阻止映像处理事件,可以尝试

$(function() { 
$(".button_air-medium").on("click",function(e) { 
e.stopPropagation(); 
parent.parent.ExecuteCommand($(this).data("commandnumber")) 
// or return false here
});
$(".button_air-medium > img").on("click",function(e) {
$(this).parent().click();
return false; 
});
});

或查找处理位置并编辑该处理程序

最新更新