点击按钮样式不断切换,下面的文字也会自动变,这是我花了十小时琢磨出来的
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>className属性</title>
<style type="text/css">
.one{background-color:red;}
.two{background-color:blue;}
</style>
</head>
<body>
<p2 id="mama" class="one">javascript</p2><br/>
<form>
<input type="button" value="点击更改" onclick="lala()">
</form>
<p id="aa">P元素Class值为:one</p>
<script type="text/javascript">
var mychar=document.getElementById("mama");
var aa=document.getElementById("aa");
function lala(){
if(mychar.className=="one")
{mychar.className="two";}
else{mychar.className="one";}
aa.innerHTML=("P元素Class值为:"+mychar.className+"<br>")
}
</script>
</body>
</html>