<input type="button" value="改变颜色" onclick="setColor()" >
<input type="button" value="改变宽高" onclick="setWandH()" >
<input type="button" value="隐藏内容" onclick="hideTxt()">
<input type="button" value="显示内容"onclick="display()" >
<input type="button" value="取消设置" onclick="setConfirm()">
</form>
<script type="text/javascript">
//定义"改变颜色"的函数
function setColor(){
var message=document.getElementById("txt")
message.style.color="red";
message.style.backgroundColor="green";
}
//定义"改变宽高"的函数
function setWandH(){
var message=document.getElementById("txt");
message.style.width=200px;
message.style.hight=200px;
}
//定义"隐藏内容"的函数
function hideTxt(){
var message=document.getElementById("txt");
message.style.display="none";
}
//定义"显示内容"的函数
function display(){
var message=document.getElementById("txt");
message.style.display="block";
}
//定义"取消设置"的函数
function setConfirm(){
var str=document.getElementById("txt");
var message=confirm("要取消设置吗?");
if(message==true)
{
str.removeAttribute("style");
}
}
</script>
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> #txt{ width: 400px; height: 400px; background-color: red; } </style> </head> <body> <input type="button" value="改变颜色" onclick="setColor()"> <input type="button" value="改变宽高" onclick="setWandH()"> <input type="button" value="隐藏内容" onclick="hideTxt()"> <input type="button" value="显示内容" onclick="display()"> <input type="button" value="取消设置" onclick="setConfirm()"> <div id="txt"></div> </form> <script type="text/javascript"> //定义"改变颜色"的函数 function setColor() { var message = document.getElementById("txt") message.style.color = "red"; message.style.backgroundColor = "green"; } //定义"改变宽高"的函数 function setWandH() { var message = document.getElementById("txt"); message.style.width = 200 + "px"; message.style.height = 200 + "px"; } //定义"隐藏内容"的函数 function hideTxt() { var message = document.getElementById("txt"); message.style.display = "none"; } //定义"显示内容"的函数 function display() { var message = document.getElementById("txt"); message.style.display = "block"; } //定义"取消设置"的函数 function setConfirm() { var str = document.getElementById("txt"); var message = confirm("要取消设置吗?"); if (message == true) { str.removeAttribute("style"); } } </script> </body> </html>
你的
message.style.width = 200 + "px";
message.style.height = 200 + "px";
这两句写错了