如何实现将应用的属性再返回到默认样式?
我更改了类属性后,怎么返回原来的属性?类似于撤销的功能?
2017-07-21
body{ font-size:16px;}
.one{
border:1px solid #eee;
width:230px;
height:50px;
background:#ccc;
color:red;
}
.two{
border:1px solid #ccc;
width:230px;
height:50px;
background:#9CF;
color:blue;
}
.Pnone{
font-size:16px;
}
</style>
</head>
<body>
<p id="p1" > JavaScript使网页显示动态效果并实现与用户交互功能。</p>
<input type="button" value="添加样式" onclick="add()"/>
<input type="button" value="返回" onclick="none1()"/>
<p id="p2" class="one">JavaScript使网页显示动态效果并实现与用户交互功能。</p>
<input type="button" value="更改外观" onclick="modify()"/>
<input type="button" value="返回" onclick="none2()"/>
<script type="text/javascript">
function add(){
var p1 = document.getElementById("p1");
p1.className="one";
}
function modify(){
var p2 = document.getElementById("p2");
p2.className="two";
}
function none1(){
var p1= document.getElementById("p1");
p1.className="Pnone";
}
function none2(){
var p2= document.getElementById("p2");
p2.className="Pnone";
}
</script>
</body>看下我下面的代码,也可以实现,但感觉太啰嗦,是否能优化一下?
举报