使用此代码,Firefox仅在按钮点击时发出警报。对于Chrome,会显示两个警报。
我希望行为与Chrome中的行为相同,点击时img
会触发某个事件(Firefox会忽略该事件)。
注意:我的实际代码更长,更实用。我把它提炼到这个较小的代码集来隔离导致我在其他地方痛苦的根行为。
<html>
<head>
<script src="http://app.essets.com/system/application/js/jquery/jquery.js" type="text/javascript"></script>
<script type='text/javascript'>
$(document).ready(function() {
$('button').click(function(){
alert('button clicked');
});
$('img').click(function(){
alert('img clicked');
});
});
</script>
</head>
<body>
<button type='button'>
<img id="1" class="moduleratingstar" src="http://app.essets.com/images/site/transactions.png">
Some text
</button>
</body>
</html>
答案 0 :(得分:1)
我认为您无法在浏览器中重现Chrome的行为 - 我甚至不确定规范中有关此的内容。
然而,您可以创建一个“假”按钮,即使用其他HTML元素,使其看起来像一个按钮。这样,实现这样的行为就不那么容易了。