Javascript--document

描述:

代表给定浏览器窗口的HTML文档

属性:

属性 描述 备注
activeElement 获取获得焦点的对象  
alinkColor 设置或获取元素中所有激活链接的颜色  
vlinkColor 设置或获取用户已经访问的链接的颜色  
linkColor 设置或获取对象链接的颜色  
bgColor 设置或获取对象背景的颜色(不推荐使用)  
fgColor 设置或获取文档的前景颜色  
cookie 设置或获取cookie的字符串值  
charset 设置或获取用于解码的字符集 utf-8
defaultCharset 从当前的区域语言中获取默认的字符集 gb2312
designMode 设置或获取当前文档是否可被编辑的值 on                可以被编辑
off/Inherit   默认的,文档不能被编辑
dir 设置或获取表明对象的阅读顺序的值  ltr:    left to right
image
rtl:    right to left
image
doctype 获取与当前文档关联的文档声明类型  返回文档类型声明
默认为NULL,
documentElement 获取对文档根节点的引用  HTML
domain 设置或获取文档的安全域名 localhost
expando 设置或获取表明是否可对象内创建任意变量的值  
implementation 获取当前文档的implementation对象   
fileCreateData 获取当前浏览文件的创建时间   
fileModifiedData 获取当前浏览文件上次修改的时间   
fileSize 获取当前浏览文件的大小   
lastModified 获取页面上次修改的时间(如果提供的话)   
referrer 获取将用户引入当前页面的URL  即:由FIrst.html页面的超级链接,链接至了Second.html页面,
     则,document.referrer的值为First.html的完整路径
parentWindow 获取容器对象所在的窗口的引用   
readyState 获取表明对象当前状态的值 

uninitialized    Object is not initialized with data.

loading            Object is loading its data.

loaded             Object has finished loading its data.

interactive      User can interact with the object even though it is not fully loaded.

complete         Object is completely initialized.

uniqueID 获取为对象自动生成的唯一标示符   
URL 设置或获取当前文档的URL   
URLUnencoded 获取文档的URL,去除所有字符编码   
protocol 设置或获取URL的协议  超文本传输协议
XMLDocument 获取由对象引出的XML文档对象模型的引用   
XSLDocument 获取对XSL文档的顶层节点的引用   

集合:

集合 描述 备注
all 返回对象所包含的所有元素(包括子元素)集合的引用 对于一个空的HTML文档,包含以下元素
!
HTML
HEAD
TITLE
BODY
SCRIPT
anchors 返回所有带有name或id属性的a对象的集合 不带有name/id属性的链接是不会计入其中的
applets 获取文档中所有applet对象的集合  
childNodes 返回document的直接后代集合  
embeds 返回所有embed的集合  
forms 返回文档中所有的form集合  
frames 返回文档中所有的frame集合  
images 返回所有的img对象的集合  
links 返回所有指定了href的a以及area对象的集合  
namespaces 获取namespace对象的集合  
scripts 获取文档中所有script对象的集合  
styleSheets 获得文档中每个link或style对象的实例对应的样式的集合  

方法:

方法 描述 备注
attachEvent 将制定的函数绑定到事件  
detachEvent 从事件中取消指定的事件  
clear 目前尚不支持  
open(mimetype,replace) 打开一个新文档,并擦除当前文档的内容 mimetype:规定正在写的文档的类型,默认为"text/html"
replace:可引用新文档从父文档继承历史条目
注意:
调用open方法打开一个新文档,
使用write时,应该在最后使用close方法来迫使其关闭文档,显示内容.
<input type="button" id="btn" value="Focus" onclick="btn_click()"/>
<script type="text/javascript">
    function btn_click(){
         var newDoc = document.open("text/html",'replace');
         var txt="<html><body>姓名:<input type='text'></body></html>";
         newDoc.write(txt);
         newDoc.close();
    }
</script>
close 关闭数据流并且强制将数据发送显示 见上格
createTextNode 创建文本字符串
var txt = document.createTextNode("document");                   
document.body.appendChild(txt);
createElement 创建元素
var txt = document.createElement("input");
//两者都可以
txt.type="text";            
//txt.setAttribute("type","text");            
document.body.appendChild(txt);
createAttribute 创建属性  
createComment 创建注释  
createStyleSheet 创建样式表  
createDocumentFragment 创建文档模块  
createEventObject 当使用fireEvent方法时用于传递事件相关信息时,生成event对象  
elementFromPoint 返回x,y坐标处的元素  
foucs 使元素获得焦点,并执行由onfous事件指定的代码
<input type="button" id="btn" value="Focus"/>
<input type="button" id="btn2" value="BTN2" 
       onfocus="btn2_focus()" />
<script type="text/javascript">
     btn.onclick=function(){
         btn2.focus();
     }
     
     function btn2_focus(){
         document.write("btn2  is focus");
         document.close();
    }
</script>
hasFocus 判断文档当前是否拥有焦点
    <input type="button" id="btn" value="Focus" onclick="btn_click()"
 onmouseover="btn_mouseover()" onmouseout="btn_mouseout()"/>
    <div id="dv" style="width:200px;height:150px;border:solid 1px black;
 display:none">
        显示出来.
    </div>
    <script type="text/javascript">
        function btn_click(){
            window.showModelessDialog("HTMLPage4.htm",window,
		"status:false;dialogWidth:300px;dialogHeight:300px");
        }
        
        function btn_mouseover(){
            if (document.hasFocus()){
                dv.style.display="block";
            }
        }
        
        function btn_mouseout(){
            dv.style.display="none";
        }
    </script>
getElementById 根据ID获取对元素的引用 document.getElementById("txt")
getElementByName 根据Name获取对元素的引用 document.getElementByName("txt")
getElementByTagName 根据元素名称,获取元素的集合 document.getElementByTagName("input")
mergeAttributes 获取所有读/写标签属性到指定元素  
execCommand 在当前文档,当前选中区或给定范围上执行命令
queryCommandEnabled 返回表明指定命令是否可于给定文档当前状态下使用execCommand命令成功执行的 Boolean 值
queryCommandIndeterm 返回表明指定命令是否处于模糊状态的 Boolean 值
queryCommandState 返回表明当前命令状态的boolean值
queryCommandSupported 返回表明命令在当前区域上是否支持的boolean值
queryCommandValue 返回文档、范围或当前选中区对于给定命令的当前值  
recalc 重新计算当前文档中的动态属性
releaseCapture 释放当前文档中对象的鼠标捕捉  
setActive 设置对象为当前,而不将对象设置为焦点
    <input type="button" id="btn" value="Focus" onclick="btn_click()" />
    <input type="button" value="btn2" id="btn2" onfocus="btn2_focus()" />
    <script type="text/javascript">
        function btn_click(){
            btn2.setActive();
        }
        
        
        function btn2_focus(){
            alert("btn2 is on focus!");
        }
    </script>

测试结果和描述不一致
write 向指定窗口的文档写入一个或多个HTML表达式 document.write("ok");
writeln 向指定窗口的文档写入一个或多个HTML表达式,追加一个换行符 document.writeln("ok");

关于execCommand及相关函数未搞定,准备专门再写一篇文章.

posted @ 2009-05-31 15:19  Localhost  阅读(1095)  评论(0编辑  收藏  举报