Home > Web Front-end > JS Tutorial > body text

Collection of Document properties and methods of javascript_Basic knowledge

WBOY
Release: 2016-05-16 18:35:44
Original
795 people have browsed it

document.title //Set the document title equivalent to the HTML title tag
document.bgColor //Set the page background color
document.fgColor //Set the foreground color (text color)
document.linkColor // Color of links that have not been clicked
document.alinkColor //Color of active links (focus is on this link)
document.vlinkColor //Color of links that have been clicked
document.URL //Set URL attributes Thus opening another webpage in the same window
document.fileCreatedDate //File creation date, read-only attribute
document.fileModifiedDate //File modification date, read-only attribute
document.charset //Set the character set Simplified Chinese: gb2312
document.fileSize //File size, read-only attribute
document.cookie //Set and read cookies

—————————————— ——————————
Common object methods

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
document.body.appendChild(oTag)
—— ————————————————————————

body-body sub-object

document.body //Specify the start and end of the document body Equivalent to body>/body>
document.body.bgColor //Set or get the background color behind the object
document.body.link //The color of unclicked links
document.body.alink //The color of the active link (the focus is on this link)
document.body.vlink //The color of the clicked link
document.body.text //The text color
document.body.innerText / /Set the text between body>.../body>
document.body.innerHTML //Set the HTML code between body>.../body>
document.body.topMargin //The top margin of the page
document.body.leftMargin //Left margin of page
document.body.rightMargin //Right margin of page
document.body.bottomMargin //Bottom margin of page
document.body.background //Background image
document.body.appendChild(oTag) //Dynamicly generate an HTML object

Common object events

document.body.onclick=”func()” //The object clicked by the mouse pointer is Trigger
document.body.onmouseover=”func()” //Trigger when the mouse pointer moves to the object
document.body.onmouseout=”func()” //Trigger when the mouse pointer moves out of the object
— ————————————————————————
location-location sub-object

document.location.hash // The part after #
document.location.host // Domain name and port number // It seems that the host name localhost is returned, but no port number is returned
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 // ? number The last part
documenty.location.reload() //Refresh the webpage
document.location.reload(URL) //Open a new webpage
document.location.assign(URL) //Open a new one Web page
document.location.replace(URL) //Open a new web page
——————————————————————————
selection-selection Sub-object
document.selection

For example:

Please select part of the text here.




script>


selection’s createRange method

document.selection.createRange() returns a TextRange object based on the current text selection, or a ControlRange object based on the control selection.

With execCommand, it is very useful in HTML editors, such as: text bold, italics, copy, paste, create hyperlinks, etc.

These seem to be only possible under IE. .

————————————————————————

images collection (images on the page)

a) Reference through collection
document.images //corresponding to the img tag on the page
document.images.length //corresponding to the number of img tags on the page
document.images[0] //1st img tags
document.images[i] //i-1th img tag

b) Directly reference
img name=”oImage”
document.images through the name attribute. oImage //document.images.name attribute

c) refers to the src attribute of the image
document.images.oImage.src //document.images.name attribute.src

d) Create an image
var oImage
oImage = new Image()
document.images.oImage.src=”1.jpg”
At the same time create an img/tag on the page corresponding to it Can display

————————————————————————-

forms collection (forms in the page)

a) Reference through collection
document.forms //corresponding to the form tag on the page
document.forms.length //corresponding to the number of /formform tags on the page
document.forms[0] / /The 1st/formform label
document.forms[i] //The i-1th/formform label
document.forms[i].length //The number of controls in the i-1th/formform
document.forms[i].elements[j] //The j-1th control in the i-1/formform

b) Directly reference the
/formform name through the label name attribute =”Myform”>input name=”myctrl”/>/form
document.Myform.myctrl //document.form name.control name

c) Access the properties of the form
document.forms [i].name //corresponds to form name>attribute
document.forms[i].action //corresponds to/formform action>attribute
document.forms[i].encoding //corresponds to/formform enctype>attribute
document.forms[i].target //corresponds to /formform target>property

document.forms[i].appendChild(oTag) //dynamically inserts a control
document.all.oDiv //Reference layer oDiv
document.all.oDiv.style.display=”” //Set the layer to be visible
document.all.oDiv.style.display=”none” //Setting the layer To hide
document.getElementId(”oDiv”) //Reference the object through getElementId
document.getElementId(”oDiv”).style=””
document.getElementId(”oDiv”).display=” none”
/*document.all represents the collection of all objects in the document
Only IE supports this attribute, so it is also used to determine the type of browser*/


Layer object 4 attributes
document.getElementById("ID").innerText //Dynamic output text
document.getElementById("ID").innerHTML //Dynamic output HTML
document.getElementById("ID") .outerText //Same as innerText
document.getElementById(”ID”).outerHTML //Same as innerHTML
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template