js document query
-------------------------------------------------- -------------------
Note: The page name attributes and JavaScript elements cited include the case name must be consistent
Otherwise, you will be prompted an error message "element references the object is empty or not"
-------------------------------------------------- -------------------
Object Properties
document.title / / set the document title is equivalent to HTML's <title> Tags
document.bgColor / / set the page background color
document.fgColor / / Set Foreground (text color)
document.linkColor / / not clicked on the link colors
document.alinkColor / / activate the link (focus in on this link) colors
document.vlinkColor / / has been clicked on the link colors
document.URL / / set the URL attribute in order to open another window in the same page
document.fileCreatedDate / / file creation date, read-only attribute
document.fileModifiedDate / / file modification date, read-only attribute
document.fileSize / / file size, read-only attribute
document.cookie / / set up and read out the cookie
document.charset / / set the character set Simplified Chinese: gb2312
-------------------------------------------------- -------------------
Common Object
document.write () / / write dynamic content to the page
document.createElement (Tag) / / create a label object html
document.getElementById (ID) / / get the value of the specified object ID
document.getElementsByName (Name) / / get the value of the specified object Name
document.body.appendChild (oTag)
-------------------------------------------------- -------------------
body-the main sub-object
document.body / / specify the main document of the beginning and the end is equivalent to <body> </ body>
document.body.bgColor / / set or access to the background color behind the object
document.body.link / / not clicked on the link colors
document.body.alink / / activate the link (focus in on this link) colors
document.body.vlink / / has been clicked on the link colors
document.body.text / / text color
document.body.innerText / / set <body> ...</ body> of the text between the
document.body.innerHTML / / set <body> ...</ body> of the HTML code between the
document.body.topMargin / / page margins
document.body.leftMargin / / page from the left
document.body.rightMargin / / from the right side of the page
document.body.bottomMargin / / page under the margin
document.body.background / / background picture
document.body.appendChild (oTag) / / dynamically generate an HTML object
Common object events
document.body.onclick = "func ()" / / click the mouse pointer is triggered
document.body.onmouseover = "func ()" / / move the mouse pointer over the object when the trigger
document.body.onmouseout = "func ()" / / object when the mouse pointer out of the trigger
-------------------------------------------------- -------------------
location-location sub-object
document.location.hash / / # of the part after the No.
document.location.host / / domain name + port number
document.location.hostname / / domain name
document.location.href / / full URL
document.location.pathname / / directory part
document.location.port / / port number
document.location.protocol / / network protocol (http:)
document.location.search / /? its part of the post -
documeny.location.reload () / / refresh the page
document.location.reload (URL) / / open a new page
document.location.assign (URL) / / open a new page
document.location.replace (URL) / / open a new page
-------------------------------------------------- -------------------
sub-object selection-constituency
document.selection
-------------------------------------------------- -------------------
images collection (page images)
a) through the collection of reference
document.images / / the corresponding labels on the page <img>
document.images.length / / the corresponding page number labels <img>
document.images [0] / / the first one <img> Tags
document.images [i] / / first i-1 months <img> Tags
b) through direct reference attributes nane
<img name="oImage">
document.images.oImage / / document.images.name property
c) picture of the src attribute references
document.images.oImage.src / / document.images.name attributes. src
d) create an image
var oImage
oImage = new Image ()
document.images.oImage.src = "1.jpg"
At the same time, the establishment of a <img> page tab to display the corresponding
<html>
<img name=oImage>
<script language="javascript">
var oImage
oImage = new Image()
document.images.oImage.src="1.jpg"
</script>
</html>
<html>
<script language="javascript">
oImage=document.caeateElement("IMG")
oImage.src="1.jpg"
document.body.appendChild(oImage)
</script>
</html>
-------------------------------------------------- --------------------
collection forms (form page)
a) through the collection of reference
document.forms / / the corresponding labels on the page <form>
document.forms.length / / the corresponding page number labels <form>
document.forms [0] / / the first one <form> Tags
document.forms [i] / / first i-1 months <form> Tags
document.forms [i]. length / / first i-1 months <form> number of controls
document.forms [i]. elements [j] / / first i-1 months <form> first j-1 months control
b) through the tag name attribute to refer directly to
<form name="Myform"> <input name="myctrl"> </ form>
document.Myform.myctrl / / document. form of. control of
c) visit the properties of the form
document.forms [i]. name / / corresponding attribute <form name>
document.forms [i]. action / / correspond to attributes <form action>
document.forms [i]. encoding / / the corresponding attribute <form enctype>
document.forms [i]. target / / correspond to attributes <form target>
document.forms [i]. appendChild (oTag) / / insert a dynamic control
-------------------------------------------------- ---------------------
<html> <!--Text Control Script --> <form name="Myform"> <input type="text" name="oText"> <input type="password" name="oPswd"> <form> <script language="javascript"> // Gets the value of a text password box document.write(document.Myform.oText.value) document.write(document.Myform.oPswd.value) </script> </html>
-------------------------------------------------- ---------------------
<html>
<!--checkbox,radio Control script -->
<form name="Myform">
<input type="checkbox" name="chk" value="1">1
<input type="checkbox" name="chk" value="2">2
</form>
<script language="javascript">
function fun(){
// Traverse the checkbox control's values and determine whether to select the
var length
length=document.forms[0].chk.length
for(i=0;i<length;i++){
v=document.forms[0].chk[i].value
b=document.forms[0].chk[i].checked
if(b)
alert(v=v+" Is selected ")
else
alert(v=v+" Do not select ")
}
}
</script>
<a href=#>ddd</a>
</html>
-------------------------------------------------- ---------------------
<html>
<!--Select Control 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">
// Walk through the select control's option item
var length
length=document.Myform.oSelect.length
for(i=0;i<length;i++)
document.write(document.Myform.oSelect[i].value)
</script>
<script language="javascript">
// Traverse the option key and whether a judgment option is selected
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">
// According to the SelectedIndex of printing a selected option
//(0 To document .Myform.oSelect.length-1)
i=document.Myform.oSelect.selectedIndex
document.write(document.Myform.oSelect[i].value)
</script>
<script language="javascript">
// The dynamic increase in select controls option item
var oOption = document.createElement("OPTION");
oOption.text="4";
oOption.value="4";
document.Myform.oSelect.add(oOption);
</script>
<html>
-------------------------------------------------- ---------------------
<Div> Text </ Div>
document.all.oDiv / / reference layer oDiv
document.all.oDiv.style.display = "" / / set layer visibility
document.all.oDiv.style.display = "none" / / set to hidden layer
document.getElementId ( "oDiv") / / object through the reference getElementId
document.getElementId ( "oDiv"). style = ""
document.getElementId ( "oDiv"). display = "none"
/ * document.all said document in a collection of all objects
Ie only support this attribute, it is also used to determine the type of browser * /
Layer 4 attributes object
document.getElementById ( "ID"). innerText / / dynamic text output
document.getElementById ( "ID"). innerHTML / / dynamic HTML output
document.getElementById ( "ID"). outerText / / with the innerText
document.getElementById ( "ID"). outerHTML / / with innerHTML
<html>
<script language="javascript">
function change(){
document.all.oDiv.style.display="none"
}
</script>
<Div>Text</Div>
</html>
<html>
<script language="javascript">
function changeText(){
document.getElementById("oDiv").innerText="NewText"
}
</script>
<Div>Text</Div>
</html>
Related Posts of js document query
-
javascript form validation (1)
<% @ Page language = "java" import = "java.util .*" pageEncoding = "utf-8"%> <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN"> <HTML> <HEAD> <TITLE> New Docu ...
-
js Simplified Traditional conversion code
js Traditional Traditional Traditional Traditional javascript code conversion conversion code Reprint Address: http://www.cnblogs.com/genson/archive/2008/04/16/1004632.html js Simplified, Traditional conversion, IE7 through, Firefox does not pass, th ...
-
struts + hibernate Page 1 js
struts + hibernate Page 1 js
-
Replace the problem with JS
"hand hand hand" want to transform for the "hand.gif hand.gif hand.gif" Started str = str.replace ( "hand", "hand.gif"); Output: hand.gif hand hand Only a replacement. . . : ( Thought of using regular, because ...
-
JavaScript's "this"
Read recently in Programming Languages Pragmatics when they see this, although does not seem to do anything worth mentioning, in order to avoid forgotten or recorded. JavaScript's this is called object. Say the image is that "." Prior t ...
-
hibernate in the get method and the difference between load method
hibernate in the get method and the load method of the fundamental difference is: If you use the load method, hibernate consider the corresponding object id (database records) are in the database must exist, so it can be assured that the use, it can ...
-
js version of Ant Colony Algorithm
js version of Ant Colony Algorithm
-
Play flash page 3 (javascript script swfobject.js2)
this.setAttribute ( "swf", this.xiSWFPath);) _19 = "<object \" "+ this.getAttribute (" id ") +" \ "classid = \" clsid: D27CDB6E-AE6D-11cf-96B8-444553540000 \ "width = \" "+ this.getA ...
-
Hibernate in the inverse and cascade
First of all, to quote another blog saying: 1.cascade ="..."? cascade is not a property of many-to-many relationship must have it just so that we insert or delete at the time like some more convenient, as long as the source of the cascade i ...
-
jboss ejb3 Message Driven Bean
Super Medium ejb hate. . . . . . . . . . . . . . . . . . . ================================================ To configure a Message Driven Bean in a different application server parameters are not the same. Currently only passed the test jboss. Messag ...













Leave a Reply