这样写是对的,但是我不明白为什么在onclick的值后面加一个(),如果不加就运行不了。
<form>
<input type="button" value="改变颜色" onclick="changeColor()">
<input type="button" value="改变宽高" onclick="changeHeight()">
<input type="button" value="隐藏内容" onclick="hide()" >
<input type="button" value="显示内容" onclick="show()" >
<input type="button" value="取消设置" onclick="reset()" >
</form>
<script type="text/javascript">
var title = document.getElementById("con")
var txt = document.getElementById("txt")
function changeColor(){
title.style = "color:red;";
}
function changeHeight(){
txt.style = "height: 300px; width: 400px;"
}
function hide(){
title.style = "display: none;"
}
function show(){
title.style = "display: block;"
}
function reset(){
var res = window.confirm("是否重置样式");
if(res){
title.style = ""
txt.style = ("style", "")
}
}
</script>