为什么我用removeAttribute("style")来恢复样式不行呢,
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
<title>让我们互动下</title>
<style type="text/css">
P{
border:1px solid red;
background:gray;
width:100px;
height:30px;
text-align:center;
line-height:30px;
}
.one{
border:2px solid blue;
background:yellow;
width:200px;
height:50px;
line-height:50px;
}
.two{
border:3px dashed yellow;
background:purple;
width:300px;
height:300px;
line-height:300px;
}
</style>
<script type="text/javascript">
function rec(){
var message=confirm("关注JS进阶篇");
if (message==true)
{
document.write("希望你学有所成");
}
else
{
document.write("希望你能关注一下");
}
}
</script>
</head>
<body>
<p id="con">JS进阶篇</p>
<form>
<input type="button" name="button" onclick="rec()" value="点击我试试" />
<input type="button" onclick="add()" value="增加样式" />
<input type="button" onclick="change()" value="改变样式" />
<input type="button" name="button" onclick="resetcss()" value="重置样式" />
</form>
<script type="text/javascript">
var mychar=document.getElementById("con");
function add(){
mychar.className="one";
}
function change(){
mychar.className="two";
}
function resetcss(){
var message1=confirm("确定要恢复原始设置?");
if (message1==true)
{
mychar.removeAttribute("style");
}
}
</script>
</body>
</html>