<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>style样式</title>
</head>
<body>
<h2 id="con">I love JavaScript</H2>
<p> JavaScript使网页显示动态效果并实现与用户交互功能。</p>
<script type="text/javascript">
var mychar=document.getElementById("con");
mychar.style.color="red";
mychar.style.backgroundColor="#CCC";
function yin(){
mychar.style.display="none";
}
function xianshi(){
mychar.style.display="block";
}
</script>
<form>
<input type="button" name="xianshi" value="xianshi" onclick="xianshi()"/>
<input type="button" name="yin" value="yin" onclick="yin()"/>
</form>
</body>
</html>
问题出在form表单,把form去掉就行
看我代码哈:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>style样式</title>
</head>
<body>
<h2 id="con">I love JavaScript</h2>
<p> JavaScript使网页显示动态效果并实现与用户交互功能。</p>
<script type="text/javascript">
var conValue = document.getElementById("con");
function setColor() {
conValue.style.color = "red";
conValue.style.backgroundColor.color = "#CCC";
}
function styleHide() {
conValue.style.display = "none";
}
function showValue() {
conValue.style.display = "block";
}
</script>
<form>
<input type="button" value="改变颜色" onclick="setColor()" />
<input type="button" value="点击隐藏" onclick="styleHide()" />
<input type="button" value="点击显示" onclick="showValue()">
</form>
</body>
</html>
你这个Id"con"没有写在input 里面啊