Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想编写一些 JavaScript 来在运行时更改 div 的 onmousedown。因此,在加载时,鼠标按下 div 会做一件事,如果调用 JavaScript 函数,鼠标按下 div 会做其他事情。这可能吗?
您可以只分配 onMouseDown 属性。
document.getElementById('myDiv').onmousedown = function() { alert('New mouse down handler.'); };
请记住,javascript 属性区分大小写。“onmousedown”全是小写。