<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
<title>display</title>
????<script?type="text/javascript">?
????????function?hidetext()??
{??
var?mychar?=?document.getElementById("con");
????????mychar.innerHTML="這個(gè)是隱藏并顯示的新內(nèi)容";
}??
function?showtext()??
{??
var?mychar?=?document.getElementById("con");
mychar.style.display="block";
????????mychar.style.color="#eeff00";
document.write("原文"+mychar.innerHTML+"</br>");
????????mychar.innerHTML="文字改了";
????????document.write("這個(gè)是顯示的新內(nèi)容"+mychar.innerHTML);
};
????</script>?
</head>?
<body>??
????<h1>JavaScript</h1>??
????<p?id="con">做為一個(gè)Web開(kāi)發(fā)師來(lái)說(shuō),如果你想提供漂亮的網(wǎng)頁(yè)、令用戶(hù)滿(mǎn)意的上網(wǎng)體驗(yàn),JavaScript是必不可少的工具。</p>?
????<form>
???????<input?type="button"?onclick="hidetext()"?value="換第一個(gè)內(nèi)容"?/>?
???????<input?type="button"?onclick="showtext()"?value="第二個(gè)內(nèi)容"?/>?
????</form>
</body>?
</html>
2014-12-19
下面這個(gè)是在w3c中對(duì)document.write()的說(shuō)明:
請(qǐng)使用 document.write() 僅僅向文檔輸出寫(xiě)內(nèi)容。
如果在文檔已完成加載后執(zhí)行 document.write,整個(gè) HTML 頁(yè)面將被覆蓋
2014-11-27
?我想應(yīng)該是document.write的問(wèn)題,使用document.write想網(wǎng)頁(yè)添加內(nèi)容,會(huì)重新加載網(wǎng)頁(yè),將之前的內(nèi)容全部覆蓋掉。