document document object - JavaScript scripting language description
----------------------------------------- ----------------------------------
Note: The name attribute of the element on the page and the name referenced by JavaScript must be consistent including size. Write
otherwise you will be prompted with an error message "The referenced element is empty or not an object"
-------------------------- ---------------------------------------------
Object Properties
tag
documen.fgcolor // >document.linkColor URL //Set URL properties to open another web page in the same window
document.fileCreatedDate // File creation date, read-only attribute
document.fileModifiedDate // File modified date, read-only attribute
document.fileSize // File size, only read attributes
document.cookie // Set and read the cookies
Document.charset // Set the character set simplified Chinese: gb2312
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- --------
Object method
document.write() //Dynamicly write content to the page
document.createElement(Tag) //Create an html tag object
document. getElementById(ID) //Get the object with the specified ID value
document.getElementsByName(Name) //Get the object with the specified Name value
---------------- -------------------------------------------------- -
images collection (images on the page)
a) Reference
document.images through the collection // The
tag
document.images on the corresponding page. length Tag
b) Directly reference
document.images.oImage //document.images.name attribute
c) Reference the src attribute of the imagedocument.images.oImage.src //document.images.nameproperty.src
d) Create an image
var oImage
oImage = new Image()
document. images.oImage.src="/1.jpg" At the same time, create a
tag on the page corresponding to it to display
-------------------------------- ----------------------------------
forms collection (forms on the page)
a) Reference
document.forms through a collection //The
tag on the corresponding pagedocument.forms.length //The number of
tags on the corresponding page
document. forms[0] / The number of controls in each
document.forms[i].elements[j] //The j-1th control in the i-1th
b) through the label name Attributes directly reference
-----------------------------------------------------------------------
<script> <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>
<script> <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+"") <BR> } <BR></script>
<script> <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>
<script> <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>
-----------------------------------------------------------------------
document.all.oDiv //引用图层oDiv
document.all.oDiv.style
document.all.oDiv.style.display="" //图层设置为可视
document.all.oDiv.style.display="none" //图层设置为隐藏
/*document.all表示document中所有对象的集合
只有ie支持此属性,因此也用来判断浏览器的种类*/