js设置鼠标悬停以更改背景颜色的详细说明
更新时间:2019年6月26日10:20:42转载作者:Code fly`
本文主要介绍js设置鼠标悬停以更改背景颜色的详细实现。本文通过示例代码进行了详细介绍,该示例代码对每个人的学习或工作都有一定的参考学习价值,需要的朋友可以参考
我在Internet上看到了很多js鼠标悬停事件,其中大多数在说了这么多之后并没有解决问题,现在直接粘贴代码以供参考
html:
this is test!
css:
方法1:
js:
$(function(){
var sign=document.getElementById("sign");
changBkColor(sign);
});
function changBkColor(obj){
obj.οnmοuseοver=function(){ this.className="over"; };//鼠标悬停事件
obj.οnmοuseοut=function(){ this.className="out"; };//鼠标离开事件
obj.οnmοusedοwn=function(){this.className="down";};//鼠标点击时触发事件
}
方法2:
jQuery
/* $(obj).hover(inFunction,outFunction)
* 等同于$(obj).mouseover().mouseout();
*/
$(function(){
$('#sign').hover(function() {
$('#sign').addClass('over');
}, function() {
$('#sign').removeClass('over').addClass('out');
});
});
以上是本文的全部内容,希望对大家的学习有所帮助,并希望您能更多地支持Scripthome。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/bofangqi/article-315459-1.html