Common built-in JavaScript objects (window, document, and form objects)

Source: Internet
Author: User

As I first learned B/S programming, I have a very simple understanding of various scripting languages.

The scripting language (JavaScript, VBScript, JScript, etc.) is between HTML, C, C ++, Java, C #, and other programming languages. Its advantage is that the Code does not have to be "compiled" as the programming language does. The Interpreter (or virtual machine) corresponding to the code is used to execute binary machine code) directly explain the execution. The program code is both a script program and a final executable file.

History:

Javascript is a scripting language. The predecessor is livescript, which is a descriptive language developed by Netscape. After Sun launched Java, Netscape introduced some object-oriented concepts in Java, re-designed them, and named them JavaScript.

Although there is a "Java" in it, it actually has little to do with Java. Java is an object-oriented language, while Javascript is based on objects and events. Javascript is an explanatory language running on the browser,It is used to generate some dynamic effects or to verify HTML forms.

In HTML, use the language attribute marked by <SCRIPT> to specify the type of the script language. Example: <script language = "JavaScript"> ...... </SCRIPT>. The language can be "JavaScript", "VBScript", or "jscript.

VBScript is a scripting language developed by Microsoft Based on VB. It is mainly used on servers as ASP scripting languages; JScript is an extended scripting language based on JavaScript. It can only be used in MS ie. Javascript is the most common. If the language attribute is not specified, the default value is "JavaScript ".

 

Next, we will introduce the most common built-in object t of javascrip:

Common built-in objects: Window objects:

Is the "ancestor" of all other objects. The reference method of a window object depends on its relationship with the current position. This object is most commonly used to open a new window from a window.

Basic Syntax: [new window =] window. open (URL, windowname [, windowpros]); it indicates the variable name of the new window object; windowname is the name of the new window; windowpros is the property of the new window (used to set the appearance of the new window );Note: If the attribute of the new window is not specified, the attribute of the new window is set according to the attribute of the parent window.

 

For example:

 

    <script language="javascript">            window.open("JStest1.htm", "newwindow", "height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");    </script>

 


Document Object:

The document object contains information about the current document, such as the title, background, color, and table.

Common Methods:

(1) Use the write ()/writeln () method to display the content in the browser.

(2) obtain the elements, attributes, and node information in the current document (for example, "document. formname" is used to obtain the form object that represents the form name on the page as fromname ).

(3) getelementbyid () and getelementbytagname (). The two methods ignore the structure of the document and can find any element in the entire HTML document (no matter where they are located in the document, for example, getelementbytagname () you can find all the <p> elements in the document ).

Example:


<HTML> 


 

From object:

Form object is a subobject under document, indicating a form object. Every form in a document is an independent and unrelated object. You can use document. formname or document. Forms [Index] to obtain a reference to a form (the index value is between 0 and the number of forms in this document ). After obtaining the form object, you can use it to obtain each form Element in the form.

 

For example, when you click OK, the document. frm. username. Value Field of the form Element username is passed to the parameter of the checkusername function.

Test:

<HTML> 
Related Article

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.