站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Javascript 专题JavaScript脚本语言描述:document 文挡对象详解

JavaScript脚本语言描述:document 文挡对象详解

摘要: JavaScript脚本语言描述:document 文挡对象详解
<tr> <td>

---------------------------------------------------------------------
注:页面上元素name属性和JavaScript引用的名称必须一致包括大小写
否则会提示你一个错误信息 "引用的元素为空或者不是对象"
---------------------------------------------------------------------

对象属性
document.title //设置文档标题等价于HTML的标签<BR>document.bgColor //设置页面背景色<BR>document.fgColor //设置前景色(文本颜色)<BR>document.linkColor //未点击过的链接颜色<BR>document.alinkColor //激活链接(焦点在此链接上)的颜色<BR>document.vlinkColor //已点击过的链接颜色<BR>document.URL //设置URL属性从而在同一窗口打开另一网页<BR>document.fileCreatedDate //文件建立日期,只读属性<BR>document.fileModifiedDate //文件修改日期,只读属性<BR>document.fileSize //文件大小,只读属性<BR>document.cookie //设置和读出cookie<BR>document.charset //设置字符集 简体中文:gb2312<BR>---------------------------------------------------------------------<BR>对象方法<BR>document.write() //动态向页面写入内容<BR>document.createElement(Tag) //创建一个html标签对象<BR>document.getElementById(ID) //获得指定ID值的对象<BR>document.getElementsByName(Name) //获得指定Name值的对象<BR>---------------------------------------------------------------------</P> <P>images集合(页面中的图象)</P> <P>a)通过集合引用<BR>document.images //对应页面上的<img>标签<BR>document.images.length //对应页面上<img>标签的个数<BR>document.images[0] //第1个<img>标签 <BR>document.images[i] //第i-1个<img>标签</P> <P>b)通过nane属性直接引用<BR><BR>document.images.oImage //document.images.name属性</P> <P>c)引用图片的src属性<BR>document.images.oImage.src //document.images.name属性.src</P> <P>d)创建一个图象<BR>var oImage<BR>oImage = new Image()<BR>document.images.oImage.src="/1.jpg"<BR>同时在页面上建立一个<img>标签与之对应就可以显示</P> <P><html><BR><BR><script language="javascript"><BR> var oImage<BR> oImage = new Image()<BR> document.images.oImage.src="/1.jpg"<BR></script><BR></html></P> <P>----------------------------------------------------------------------</P> <P>forms集合(页面中的表单)</P> <P>a)通过集合引用<BR>document.forms //对应页面上的<form>标签<BR>document.forms.length //对应页面上<form>标签的个数<BR>document.forms[0] //第1个<form>标签<BR>document.forms[i] //第i-1个<form>标签<BR>document.forms[i].length //第i-1个<form>中的控件数<BR>document.forms[i].elements[j] //第i-1个<form>中第j-1个控件</P> <P>b)通过标签name属性直接引用<BR><form name="Myform"><input name="myctrl"></form><BR>document.Myform.myctrl //document.表单名.控件名</P> <P>-----------------------------------------------------------------------<BR><html><BR> <P><script language="javascript"><BR> //遍历select控件的option项<BR> var length<BR> length=document.Myform.oSelect.length<BR> for(i=0;i<length;i++)<BR> document.write(document.Myform.oSelect[i].value)<BR></script></P> <P><script language="javascript"><BR> //遍历option项并且判断某个option是否被选中<BR> for(i=0;i<document.Myform.oSelect.length;i++){<BR> if(document.Myform.oSelect[i].selected!=true)<BR> document.write(document.Myform.oSelect[i].value)<BR> else<BR> document.write("<font color=red>"+document.Myform.oSelect[i].value+"</font>") <BR> }<BR></script></P> <P><script language="javascript"><BR> //根据SelectedIndex打印出选中的option<BR> //(0到document.Myform.oSelect.length-1)<BR> i=document.Myform.oSelect.selectedIndex<BR> document.write(document.Myform.oSelect[i].value)<BR></script></P> <P><script language="javascript"><BR> //动态增加select控件的option项<BR> var oOption = document.createElement("OPTION");<BR> oOption.text="4";<BR> oOption.value="4";<BR> document.Myform.oSelect.add(oOption);<BR></script><BR><html><BR>-----------------------------------------------------------------------<BR><Div id="oDiv">Text</Div><BR>document.all.oDiv //引用图层oDiv<BR>document.all.oDiv.style <BR>document.all.oDiv.style.display="" //图层设置为可视<BR>document.all.oDiv.style.display="none" //图层设置为隐藏<BR>/*document.all表示document中所有对象的集合<BR>只有ie支持此属性,因此也用来判断浏览器的种类*/</P></td> </tr> </table> <br> <a href="/javascript/index.html">↑返回目录</a> <BR> 前一篇: <a href='/javascript/1/13610.html'>用JavaScript脚本将当地时间转换成其它时区 </a> <br> 后一篇: <a href='/javascript/1/13612.html'>javascript事件查询综合 </a> </div> <!-- end: 正文 --> <!-- #EndEditable --> <!-- begin: footer --> <div id=footer><center> <a href="http://www.javanb.com/index.html">首页</a> | <a href="http://www.javanb.com/java-sitemap-bd.html">全站 Sitemap</a> | <a href="http://www.javanb.com/contact.html">联系我们</a> | <a href="#" onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.javanb.com/');return(false);">设为首页</a> | <a href="#" onclick="window.external.AddFavorite('http://www.javanb.com/', 'Java 编程资料牛鼻站');return false;">收藏本站</a> <br>版权所有 Copyright © 2006-2007, Java 编程资料牛鼻站, All rights reserved <br>   </center></div> <!-- end: footer --> </div> </body><!-- #EndTemplate --></html>