仅供参考!
<form>
<!--当点击相应按钮,执行相应操作,为按钮添加相应事件-->
<input type="button" value="改变颜色" onclick = "updateColor()">
<input type="button" value="改变宽高" onclick = "updateWidthAndHeight()">
<input type="button" value="隐藏内容" onclick = "hidingContent()">
<input type="button" value="显示内容" onclick = "displayContent()">
<input type="button" value="取消设置" onclick = "cancelSet()">
</form>
<script type="text/javascript">
//定义"改变颜色"的函数
var txt_document = document.getElementById('txt');
function updateColor(){
txt_document.style.color = "green";
txt_document.style.backgroundColor = "black";
}
//定义"改变宽高"的函数
function updateWidthAndHeight(){
txt_document.style.width = "200px";
txt_document.style.height = "300px";
}
//定义"隐藏内容"的函数
function hidingContent(){
txt_document.style.display="none";
}
//定义"显示内容"的函数
function displayContent(){
txt_document.style.display="block";
}
//定义"取消设置"的函数
function cancelSet(){
var confirm_res = window.confirm("确定要取消设置吗?");
if(confirm_res){
txt_document.removeAttribute("style");
}else{
return false;
}
}
</script>