怎么设置多次点击按钮,样式可以来回切换,同时document.write描述样式的文字也能变化?我这个代码哪里有问题?
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>654613</title>
<style type="text/css">
.one{
color:red;
background-color:green;
font-size:20px;
width=300px;
height=100px;
}
.two{
color:blue;
background-color:pink;
font-size:50px;
width=500px;
height=150px;
}
</style>
<body>
<div id="div1" style="text-align:center;">
<p>样式可以转换,快来试试</p><br />
<input name="button" type="button" onclick="typeform()" value="点我转换" />
</div>
<script>
var mm=document.getElementById("div1");
mm.className="one"
document.write("现在的样式ID是:"+mm.className)
function typeform()
{
if(mm.className="one")
{
mm.className="two"
}
else
{
mm.className="one"
}
}
</script>
</body>
</html>只能点一次,再点就没反应了。当我的div样式是two时,应该触发else了呀?同时document.write的文字也不能改变(一直是one),难道不应该随着className变化吗。