国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > JS > 正文

document.open() 與 document.write()的區(qū)別

2024-09-06 12:41:44
字體:
供稿:網(wǎng)友
document.open()  打開一個新的空白文檔,在IE下,open有兩個默認(rèn)參數(shù),相當(dāng)于document.open("text/html",'""),第二個參數(shù)只有一個值可選:replace,如果啟用了該值,則新建的文檔會覆蓋當(dāng)前頁面的文檔(相當(dāng)于清空了原文檔里的所有元素,且不能后退即,瀏覽器的后退按鈕不可用);
看一個例子:

<SCRIPT LANGUAGE="JavaScript">
<!--
function test(){
 document.open("text/html","replace");
 document.writeln(Math.random());
 document.write("<input type='button' value='back(第二個按鈕)' onclick='history.back()'>")
 document.close();
 document.open("text/html","");
 document.writeln(Math.random());
 document.write("<input type='button' value='back(第三個按鈕)' onclick='history.back()'>")
 document.close();
 document.open("text/html","");
 document.writeln(Math.random());
 document.write("<input type='button' value='back(第四個按鈕)' onclick='history.back()'>")
 document.close();
}
//-->
</SCRIPT>
<input type="button" value="第一個按鈕" onclick="test()">

平常都不寫document.open() 與 document.close(),因為瀏覽器會在write之前先open一個文檔,再把write的內(nèi)容輸出到原文檔里面。write結(jié)束后,默認(rèn)是不會有close的,否則第二行document.write的時候就會覆蓋之前的write。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 紫阳县| 新平| 渝北区| 磴口县| 罗甸县| 新巴尔虎右旗| 东至县| 崇明县| 尉犁县| 宁阳县| 镇巴县| 江陵县| 临泽县| 左权县| 松阳县| 祁阳县| 巧家县| 大邑县| 安岳县| 汉阴县| 泌阳县| 卢龙县| 金沙县| 新晃| 深圳市| 闽清县| 马公市| 西乡县| 沙河市| 龙海市| 鲁山县| 呼伦贝尔市| 涟水县| 永福县| 务川| 宝丰县| 普安县| 扎鲁特旗| 班玛县| 芦山县| 新和县|