扫码关注官方订阅号
一般通过这样去模拟css中的事件,那么js 中的onmouseover如何模拟?
欢迎选择我的课程,让我们一起见证您的进步~~
如果你是想在 chrome 中調試時觸發事件,例如 mouseover ,可以在 console 中這麼做:
chrome
mouseover
console
<p id="box"></p>
document.getElementById('box').onmouseover = function() { console.log('mouseover event trigger'); };
Chrome Devloper Tool -> Console
Chrome Devloper Tool
Console
$("#box").onmouseover()
這裡的 $ 是 Chrome 內建選取元素的方法,不是 jQuery 。
$
Chrome
jQuery
Event.createEvent()
<!DOCTYPE html><html><head><style type="text/css">
#p1{width: 200px;height: 200px;background-color: blue;}
</style></head><body><p id="p1"></p></body><script type="text/javascript">
var op=document.getElementById('p1'); op.onmouseover=function() { op.style.background='red'; } op.onmouseout=function() { op.style.background='blue'; }
</script></html>
用JS很容易实现啊。如上。
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
如果你是想在
chrome中調試時觸發事件,例如mouseover,可以在console中這麼做:Chrome Devloper Tool->Console這裡的
$是Chrome內建選取元素的方法,不是jQuery。Event.createEvent()
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<p id="p1"></p>
</body>
<script type="text/javascript">
</script>
</html>
用JS很容易实现啊。如上。