Document 对象方法
close() //关闭用 document.open() 方法打开的输出流,并显示选定的数据。getElementById() //返回对拥有指定 id 的第一个对象的引用。
getElementsByName() //返回带有指定名称的对象集合。
getElementsByTagName() //返回带有指定标签名的对象集合。
open() //打开一个流,以收集来自任何 document.write() 或 document.writeln() 方法的输出。
write() //向文档写 HTML 表达式 或 JavaScript 代码。
writeln() //等同于 write() 方法,不同的是在每个表达式之后写一个换行符。
close()
newDoc.close();
该方法将关闭 open() 方法打开的文档流,并强制地显示出所有缓存的输出内容。如果您使用 write() 方法动态地输出一个文档,必须记住当你这么做的时候要调用 close() 方法,以确保所有文档内容都能显示。
一旦调用了 close(),就不应该再次调用 write(),因为这会隐式地调用 open() 来擦除当前文档并开始一个新的文档。
getElementById()
document.getElementById(id)//最有效的在文档中查找带有参数ID的元素
getElementsByName()
document.getElementsByName(name)//注意这个函数会返回一个数组 可用 [] 访问当中内容
getElementsByTagName()
document.getElementsByTagName("input");//返回页面标签集合 , 数组访问方法同上
open()
function createNewDoc()
{
var newDoc=document.open("text/html","replace",'width=200,height=200');//这是弹出窗口 , 如果不弹窗则在当前打开
var txt="<html><body>Learning about the DOM is FUN!</body></html>";
newDoc.write(txt);
newDoc.close();
}
后两个暂时不写 了, 为啥 , 因为暂时用不到
页:
[1]