<!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> <input type="button" value="sdfdfas" onclick="hidden()"/> <script type="text/javascript"> var i = document.getElementById("con"); i.style.color="red"; i.style.backgroundColor="#ccc"; function hidden(){ i.style.display="none"; } </script> </body> </html>
hidden是关键字,不能当函数名 换一个其他字母就好啦!!!
我这又可以?
<h2 id="con">I love JavaScript</h2>
<p>JavaScript使网页显示动态效果并实现与用户交互功能。</p>
<input type="button" value="隐藏内容" onclick="nshow()"/>
<script type="text/javascript">
var tt=document.getElementById("con");
tt.style.backgroundClor="#CCC";
tt.style.color="red";
function nshow(){
tt.style.display="none";
}
</script>
</body>
</html>