removeAttribute
<form>
<!--当点击相应按钮,执行相应操作,为按钮添加相应事件-->
<input type="button" value="改变颜色" onclick="setColor()" >
<input type="button" value="改变宽高" onclick="setWh()" >
<input type="button" value="隐藏内容" onclick="setHide()" >
<input type="button" value="显示内容" onclick="setDisplay()" >
<input type="button" value="取消设置" onclick="setReset()" >
</form>
<script type="text/javascript">
//定义"改变颜色"的函数
function setColor()
{
var sc = document.getElementById("txt");
sc.style.color="red";
sc.style.backgroundColor="#ccc";
}
function setWh()
{
var sw = document.getElementById("txt");
sw.style.width="500px";
sw.style.height="600px";
}
function setHide()
{
var yc = document.getElementById("txt").style.display="none";
}
function setDisplay()
{
var xs = document.getElementById("txt").style.display="block";
}
function setReset()
{
var qx = confirm("您确定将以上所有的设置恢复原始值?")
if(qx==true)
{
txt.removeAttribute("style");
}
}
</script>