JavaScript Document Object

Source: Internet
Author: User

1.document Properties

    • Cookie-User Cookie
    • Title-the text defined in the title tag of the current page
    • URL--The URL of the current page

Document represents the contents of an HTML document, so it can be used to represent elements that are loaded in the document, all accessed through a collection.

    • Anchors-a collection of all anchors (a name= "Aname") in the document
    • Applets--a collection of content represented by all applet tags in the document
    • Embeds--a collection of content represented by all embed tags in a document
    • Forms-a collection of the content represented by all form labels in a document
    • Images--a collection of content represented by all the image tags in the document
    • Links--A collection of content represented by all a (link) tags in a document

2.document function

    • JavaScript Write () function
    • JavaScript Writeln () function
    • JavaScript Document.open () function
    • JavaScript Document.close () function

A. document.write-writing a string in a document

Write function Syntax

  document.write(str);

Write function Arguments
    • STR--A string to be written in the document

B.document.writeln--Writes a string in the document and adds a newline character to the end of the string

C.document.open--Open a document already loaded

Example

  varwin = window.open("about:blank","dreamdu");

  win.document.open();

  win.document.write("welcome to dreamdu!");

  win.document.close();

Start by creating a new blank document, opening open, writing the content, and closing the document close when finished.

document.open function Syntax

   window.document.open();

D.document.close--Used to close the document opened by the Document.open method

document.close window . document functional . language close ( ) ;
 
3.
Use document to index elements within a page

You can use the collection of elements in a number or name index page, and the properties of each element become the properties of the corresponding object in the collection.

Example
<form name="form1"><a href="http://www.dreamdu.com/xhtml/" name="a1">xhtml</a></form><form name="form2"><a href="http://www.dreamdu.com/css/" name="a2">css</a></form><form name="form3"><a href="http://www.dreamdu.com/javascript/" name="a3">javascript</a></form><input type="button" value="显示第二个表单的名称" onclick="alert(document.forms[1].name)" /><input type="button" value="显示第二个表单的名称第二种方法" onclick="alert(document.forms[‘form2‘].name)" /><input type="button" value="显示第三个链接的名称" onclick="alert(document.links[2].name)" /><input type="button" value="显示第三个链接的名称第二种方法" onclick="alert(document.links[‘a3‘].name)" /><input type="button" value="显示第三个链接href属性的值" onclick="alert(document.links[2].href)" />

Method that represents the second form: document.forms[1] or document.forms["Form2"]

Method that represents the third link: document.links[2] or document.links["A3"]

A method that represents the third link href attribute: document.links[2].href

JavaScript Document Object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.