document對象包含一些屬性,如:domain,referrer。
下面代碼遍歷了document中包含的所有對象,另外,打開一個新的窗口,在新的窗口中用document對象的open方法,打開新的文檔,在文檔里輸入了標簽,最后用close方法關閉文檔。
通過document.getElementById document.getElementsByName可以找到指定id或者屬性名稱的標簽。
代碼:
<!DOCTYPE HTML><HTML> <HEAD> <TITLE id="title1"> New Document </TITLE> <META CHARSET="gb2312"> <script language="javascript"> function openWinDoc() { myWin = window.open("","","width=500,height=500"); myWin.document.open("text/html","replace"); myWin.document.write("<html><head><title>新文檔</title></head>"); myWin.document.write("<body>這是一個新的文檔</body></html>"); myWin.document.close(); } function getId() { var c = document.getElementById("title1").tagName; alert("窗口標題:" + c); } function getName() { var c = document.getElementsByName("blist").length; alert("按鈕個數:" + c); } </script> </HEAD> <BODY> <input type="button" value="打開新窗口-文檔" onclick="openWinDoc()"><br><hr> <input type="button" name="blist" value="用id獲取窗口標題的標簽" onclick="getId()"><br><hr> <input type="button" name="blist" value="用name獲取button屬性名為blist的按鈕數量" onclick="getName()"><br><hr> <script language="Javascript"> /* domain: 服務器的網域名 referrer: 連接這個網頁的url title: 標題 url:網頁url */ for(o in window.document) if(typeof(window.document[o]) != "unknown" ) window.document.write(o + ":->" + window.document[o] + "<br>"); else window.document.write(o + ":-><br>"); </script> </BODY></HTML>
新聞熱點
疑難解答