2017-08-09 117 views
2

我有这个按钮:为什么这个inline stopPropagation方法调用不起作用?

<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属性我叫两个功能ExecuteCommandstopPropagation

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

任何想法为什么stopPropagation方法不起作用?

+0

我想'stopPropagation()'属于jQuery的。相反,只需使用'return false;'它应该诀窍 – ihpar

+0

你需要问自己这里的问题是在这种情况下'事件'是什么? – Liam

回答

1

有可能没有event可在浏览器中内嵌处理器使用的是

,如果你使用

<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 
    }); 
}); 

你将有一个更简单的时间想要停止处理您可以尝试的事件的图像

$(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; 
    }); 
}); 

或找到它的处理和编辑处理

+0

我尝试你的例子,但它剂量工作 – Michael

+1

“不行”是什么意思?控制台中的错误?没有?改变它返回false,它确实有效?随着你给的代码我不能告诉 – mplungjan

+0

我添加了返回false的地方你的意见,我没有在控制台中的任何错误,并在按钮下的元素是影响。 – Michael