<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312">
<title>display</title>
????<script?type="text/javascript">?
????????function?hidetext()??
{??
var?mychar?=?document.getElementById("con");
????????mychar.sytle.display="none";
}??
function?showtext()??
{??
var?mychar?=?document.getElementById("con");
????????mychat.sytle.display="block";
}
????</script>?
</head>?
<body>??
????<h1>JavaScript</h1>??
????<p?id="con">做為一個(gè)Web開發(fā)師來說,如果你想提供漂亮的網(wǎng)頁、令用戶滿意的上網(wǎng)體驗(yàn),JavaScript是必不可少的工具。</p>?
????<form>
???????<input?type="button"?onclick="hidetext()"?value="隱藏內(nèi)容"?/>?
???????<input?type="button"?onclick="showtext()"?value="顯示內(nèi)容"?/>?
????</form>
</body>?
</html>
2017-06-17
? ?mychar.sytle.display="none"; ?里面的單詞拼寫錯(cuò)誤 應(yīng)該是style而不是sytle!
2017-06-17
mychat.sytle.display="block"; ?這里面的兩個(gè)單詞都是錯(cuò)誤的 mychar ?和 style!!!
2017-06-17
<script?type="text/javascript">?
????????function?hidetext()??
????????{??
????????var?mychar?=?document.getElementById("con").sytle.display="none";
????????mychar.sytle.display="none";
????????}??
????????function?showtext()??
????????{??
????????var?mychar?=?document.getElementById("con")?.sytle.display="block";
????????
????????}
????</script>?
必需要有這個(gè)格式 document.getElementById("XX")sytle.display="none";