国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 绥滨县| 晋江市| 大洼县| 文昌市| 徐水县| 台南县| 吉木萨尔县| 乐安县| 延寿县| 米林县| 宣武区| 贡山| 双城市| 呼玛县| 湖口县| 萨迦县| 固安县| 弥勒县| 灌阳县| 扬州市| 凤台县| 克东县| 札达县| 开化县| 扎鲁特旗| 宝坻区| 乐昌市| 河曲县| 拜泉县| 鹿泉市| 阜城县| 黄大仙区| 如皋市| 安徽省| 清流县| 临夏县| 姜堰市| 甘孜县| 建德市| 缙云县| 商河县|