javascript:改变css

<html> <head> <title>test</title> <style> #subnav { color:#d5d5d5; margin:8px 0px; border:none; position:relative; } #subnav a { background: url(../images/arr_sqblue.gif) no-repeat 8px 4px; _background-position:8px 2px; padding:0px 10px 0px 20px; } #subnav a:hover { background: url(../images/arr_sqbrown.gif) no-repeat 8px 4px; _background-position:8px 2px; } #subnav a.current { color:#000; font-weight:bold; } </style> <head> <body> <div id="subnav"> <a href="#" mce_href="#" id="t0" onclick="change(0)">test0</a>| <a href="#" mce_href="#" id="t1" onclick="change(1)">test1</a>| <a href="#" mce_href="#" id="t2" onclick="change(2)" class="current">test2</a>| </div> <script type="text/javascript"> change = function(no){ for(var i=0;i<3;i++){ if(i == no){ document.getElementById("t"+i).setAttribute("class","current"); //Mozilla设置class的方法 document.getElementById("t"+i).setAttribute("className","current"); //IE设置class的方法</p> }else{ document.getElementById("t"+i).setAttribute("class",""); //Mozilla设置class的方法 document.getElementById("t"+i).setAttribute("className",""); //IE设置class的方法</p> } } //还可以根据no的值决定请求的url } </script> </body> </html>

你可能感兴趣的:(JavaScript,function,css,url,Class)