document 文挡对象 - JavaScript脚本语言描述
对象属性
- document.title
- document.bgColor
- document.fgColor
- document.linkColor
- document.alinkColor
- document.vlinkColor
- document.URL
- document.fileCreatedDate
- document.fileModifiedDate
- document.fileSize
- document.cookie
- document.charset
对象方法
- document.write()
- document.createElement(Tag)
- document.getElementById(ID)
- document.getElementsByName(Name)
images集合(页面中的图象)
a)通过集合引用
- document.images
- document.images.length
- document.images[0]
- document.images[i]
b)通过nane属性直接引用
- <img name="oImage">
- document.images.oImage
c)引用图片的src属性
- document.images.oImage.src
d)创建一个图象
- var oImage
- oImage = new Image()
- document.images.oImage.src="/1.jpg"
同时在页面上建立一个<img>标签与之对应就可以显示
- <html>
- <img name=oImage>
- <script language="javascript">
- var oImage
- oImage = new Image()
- document.images.oImage.src="/1.jpg"
- </script>
- </html>
forms集合(页面中的表单)
a)通过集合引用
- document.forms
- document.forms.length
- document.forms[0]
- document.forms[i]
- document.forms[i].length
- document.forms[i].elements[j]
b)通过标签name属性直接引用
- <form name="Myform"><input name="myctrl"></form>
- document.Myform.myctrl
- <html>
- <!--Text控件相关Script-->
- <form name="Myform">
- <input type="text" name="oText">
- <input type="password" name="oPswd">
- <form>
- <script language="javascript">
- document.write(document.Myform.oText.value)
- document.write(document.Myform.oPswd.value)
- </script>
- </html>
- <html>
- <!--Select控件相关Script-->
- <form name="Myform">
- <select name="oSelect">
- <option value="1">1</option>
- <option value="2">2</option>
- <option value="3">3</option>
- </select>
- </form>
-
- <script language="javascript">
-
- var length
- length=document.Myform.oSelect.length
- for(i=0;i<length;i++)
- document.write(document.Myform.oSelect[i].value)
- </script>
-
- <script language="javascript">
-
- for(i=0;i<document.Myform.oSelect.length;i++){
- if(document.Myform.oSelect[i].selected!=true)
- document.write(document.Myform.oSelect[i].value)
- else
- document.write("<font color=red>"+document.Myform.oSelect[i].value+"</font>")
- }
- </script>
-
- <script language="javascript">
-
-
- i=document.Myform.oSelect.selectedIndex
- document.write(document.Myform.oSelect[i].value)
- </script>
-
- <script language="javascript">
-
- var oOption = document.createElement("OPTION");
- oOption.text="4";
- oOption.value="4";
- document.Myform.oSelect.add(oOption);
- </script>
- <html>
- <Div id="oDiv">Text</Div>
- document.all.oDiv
- document.all.oDiv.style
- document.all.oDiv.style.display=""
- document.all.oDiv.style.display="none"
/*document.all表示document中所有对象的集合
只有ie支持此属性,因此也用来判断浏览器的种类*/ javascript中document学习
原文:http://www.cnblogs.com/qiangupc/p/4193414.html