日期:2014-05-17 浏览次数:20683 次
var spans = document.getElementsByTagName("span"); for (var j = 0; j < spans.length; j++) { spans[j].style.color = "blue"; spans[j].onmouseover = function overThis(){ this.style.color = "red"; this.style.cursor="hand"; this.style.textDecoration = "underline"; }; spans[j].onmouseout = function outThis(){ this.style.color = "blue"; this.style.cursor=""; this.style.textDecoration = "none"; } }
<html> <head> <title></title> </head> <body> <span>aaa </span><br> <span>bbb </span><br> <span>ccc </span><br> <span>ddd </span><br> <span>eee </span><br> </body> <script> function overThis(){ this.style.color = "red"; this.style.cursor="hand"; this.style.textDecoration = "underline"; } function outThis(){ this.style.color = "blue"; this.style.cursor=""; this.style.textDecoration = "none"; } var spans = document.getElementsByTagName("span"); for (var j = 0; j < spans.length; j++) { spans[j].style.color = "blue"; spans[j].onmouseover = overThis; spans[j].onmouseout = outThis; } </script> </html>
------解决方案--------------------
对不起,后面的textDecoration忘了加this.style.了。
color = "blue"; onmouseover: expression(onmouseover=function (){this.style.color ='red';this.style.cursor='hand';this.style.textDecoration = 'underline'}); onmouseout: expression(onmouseout=function (){this.style.color ='blue';this.style.cursor='';this.style.textDecoration = ''});
------解决方案--------------------
SPAN{ star:expression( onmouseover=function(){ this.style.color = "red"; this.style.cursor="hand"; this.style.textDecoration = "underline"; }, onmouseout=function(){ this.style.color = "blue"; this.style.cursor=""; this.style.textDecoration = "none"; } ); color:blue }