gpt4 book ai didi

javascript - Firefox addeventlistener ('mouseover' ,...) 在

转载 作者:行者123 更新时间:2023-11-29 15:41:14 25 4
gpt4 key购买 nike

以下javascript成功触发alert<button>适用于 Chrome 但不适用于 Firefox 的元素;使用 Firefox,alert未触发:

element.addEventListener('mouseover', function(){ alert('mouseover') }, false);

当我替换 element 时html 到 <span> , 事件触发了预期的 alert在 Firefox 中,正如预期的那样。

违规的 html:

不工作 html

<button id="button-upload"><span>upload</span></button>

工作 html

<span id="button-upload"><span>upload</span></span>

在 firefox 中,事件不会冒泡到 child 的按钮吗?

如果是这样,是否有解决方法 - 除了替换 buttonspan由于 CSS。

最佳答案

你可以这样做吗?

html:

<div><button id="button-upload"><span>upload</span></button></div>

JavaScript:

document.getElementById('button-upload').parentNode.addEventListener('mouseover', function(){ alert('mouseover') }, false);

关于javascript - Firefox addeventlistener ('mouseover' ,...) 在 <button> 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18645598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com