javascript - 使用 .attr 更改 onMouseOver

标签 javascript jquery internet-explorer attributes onmouseover

所以,我将这个 opDiv1 设置为 onMouseOver="mhover(opDiv1)" 但我想更改函数 onMouseOver 如果浏览器是IE。

我正在使用这个:

if (ie!=undefined) { //If IE detected
        $('#opDiv1').attr("onMouseOver","mhover_ie('opDiv1')")
}

但是,如果我使用 IE(任何版本),它不会改变 onMouseOver 的功能

最佳答案

你可以这样改变 IE 的 onMouseOver-event

if (ie != undefined) {
    document.getElementById('opDiv1').onmouseover = function () { mhover_ie('opDiv1'); };
};

信息: 将函数分配给 onclick 属性不会向 DOM 节点添加属性。

关于javascript - 使用 .attr 更改 onMouseOver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18230225/

相关文章:

jquery - 如何在HTML5 + CSS3中模拟类似窗口的内容区域剪切

jquery - 预检响应中的 Access-Control-Allow-Methods 不允许方法 DELETE

CSS 溢出 :hidden not working in IE and position:relative makes no difference

html - IE 9 及以上版本与 html 表格元素的行为不同

javascript - IE 9 偶尔无法加载 javascript 资源

javascript - 如何以简单的方式将函数转换为 RequireJS 中的模块?

javascript - 使用 Sanity npm 包开 Jest 模拟测试

javascript - 如何正确更新对象的状态(ReactJS + Redux)?

javascript - 使用表单 : Executing the ID then the php action

javascript - 单击 <a> 链接时如何关闭导航栏?