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

首頁 > 編程 > JavaScript > 正文

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

2019-11-21 01:58:43
字體:
來源:轉載
供稿:網友
document.open()  打開一個新的空白文檔,在IE下,open有兩個默認參數,相當于document.open("text/html",'""),第二個參數只有一個值可選:replace,如果啟用了該值,則新建的文檔會覆蓋當前頁面的文檔(相當于清空了原文檔里的所有元素,且不能后退即,瀏覽器的后退按鈕不可用);
看一個例子:

<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的內容輸出到原文檔里面。write結束后,默認是不會有close的,否則第二行document.write的時候就會覆蓋之前的write。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇沅| 临江市| 连州市| 化德县| 达孜县| 澎湖县| 红桥区| 胶州市| 颍上县| 和政县| 沿河| 金堂县| 克什克腾旗| 天峨县| 同仁县| 广宁县| 金坛市| 教育| 江门市| 越西县| 昂仁县| 二连浩特市| 阿勒泰市| 乌海市| 绥芬河市| 宁津县| 西和县| 唐山市| 平度市| 新沂市| 龙泉市| 建昌县| 通道| 阳山县| 印江| 姜堰市| 永兴县| 荣昌县| 班玛县| 乐安县| 崇明县|