Document 对象属性及方法小结
来源:互联网 发布:闪电抢购软件 编辑:程序博客网 时间:2024/05/17 08:27
1 Browser对象Window: closedNavigatorScreenHistoryLocation2 Document集合:window.documentdocument.all[i] , document.all[name] , document.all.tags[tagname]document.anchors[] , document.anchors.length , document.anchors[0].innerHTMLdocument.forms[], document.forms.length, document.forms[0].name, document.getElementById("form1").name document.images[]不包含由<object>标记定义的图像document.images.lengthdocument.links[] 返回文档中所有Area和Link对象的引用, document.link[0].id属性:bodydocument.cookiedocument.domaindocument.lastModifieddocument.referrerdocument.titledocument.URL方法document.close()document.getElementById("maindiv")document.ElementsByName("xiaoxiao")document.getElementsByTagName("input")document.open(mimetype, replace);mimetype : 文档类型,默认 "text/html"; replace : 参数设置后,可引起新文 档从父文档继承历史条目重要事项:调用 open() 方法打开一个新文档并且用 write() 方法设置文档内容后,必须记住用 close 方法关闭文档,并迫使其内容显示出来。<html><head><script type="text/javascript">function createNewDoc() { var newDoc=document.open("text/html","replace"); var txt="<html><body>Learning about the DOM is FUN!</body></html>"; newDoc.write(txt); newDoc.close(); }</script></head><body><input type="button" value="Write to a new document"onclick="createNewDoc()"></body></html><html><head><script type="text/javascript">function winTest() { var txt1 = "This is a new window."; var txt2 = "This is a test."; win.document.open("text/html","replace"); win.document.writeln(txt1); win.document.write(txt2); win.document.close(); }</script></head><body><script type="text/javascript">var win=window.open('','','width=200,height=200');winTest();</script></body></html>document.write(exp1, exp2, exp3) : 向输出流写文本,HTML, 或多参数使用document.writeln()与write()不同的是换行