您的位置:首页 > Web前端 > JavaScript

javascript:改变css

2009-04-29 17:46 337 查看
<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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: