CSS和JS初步结合使用-鼠标改变事件

mac2024-08-18  63

CSS和JS初步结合使用-鼠标改变事件

12

1

从上查询时,发现$(this).addClass("s")报错,$ is not defined;原来必须要导入JQuery;

2

后来才知道JS的用法为: var list = document.getElementById("up").getElementsByTagName("span"); //遍历所有li节点 for(var i=0;i<list.length;i++){ //添加鼠标移入事件 list[i].onmouseover=function(){ this.style.backgroundColor="#6495ed"; // this.style.fontSize="20px"; } //添加鼠标移出事件 list[i].onmouseout=function(){ this.style.backgroundColor="#ffffff"; }
最新回复(0)