Common JavaScript labels and Methods Summary _ javascript skills

Source: Internet
Author: User
JavaScript can be directly interpreted and executed by the browser, which can better reduce the server pressure and improve the program running efficiency. The following small series share common JavaScript labels and methods through this article, come and learn with friends. What is javascript?

(1) JavaScript is a scripting language based on Object and Event-Driven with secure performance.

(2) JavaScript is a scripting language developed by Netscape. Programs Written in JavaScript can be embedded in HTML pages and interpreted and executed directly in browsers.

(3) JavaScript can be directly interpreted and executed by the browser, which can reduce the pressure on the server and improve the efficiency of the process.

// Event (event listening ):

// Tag object. event listening. function () {code executed, search for object, find attribute, and change attribute };

Event source. Trigger an event. Call a method. Locate the Execution Code to find the object, find the attribute, and change the attribute (or use the attribute to add, delete, modify, and query)

Onmouseover move the mouse over an element

Onmouseout move an element

Press the onkeydown keyboard (that is, keep pressing)

Press the onkeypress key to release it (that is, click it to release it)

The oonkeyup keyboard is released (that is, when it is released)

Click onclick, and click Next (click)

Onmousedown: press the mouse button (do not move)

Onmousemove move the mouse (move and press either)

Onmouseout move the mouse over an element (when the mouse is placed)

Onmouseup: Click to release the mouse (when the mouse is released)

The onresize window or frame is resized again.

Window. onresize

Onsubmit form submission

Onblur element loses focus

Onfocus element obtains focus

The width and height of the blank area of the browser (that is, the width and height of the browser)

Width: document.doc umentElement. clientWidth;

High: document.doc umentElement. clientHeight;

// Method for obtaining objects:

// Specify parameter Doc ument. getElementById ('miao'); // window can be omitted

Document. getElementById ('miao'); // ID is unique and cannot conflict. Therefore, an object value is obtained, not an array.

Document. getElementsByTagName ("a"); // The tag name is not unique. Obtain all a tag objects and generate an array.

Document. getElementsByClassName ("a"); // className is not unique. Retrieve all tag objects whose className is a to generate an array.

Document. getElementsByName ("a"); // The Name attribute is not unique. Obtain all tag objects whose names are a and generate an array.

Is the entire tag.

After obtaining the object, if you want to obtain the content in the tag, you can call the innerHTML attribute of the object.

Tag object. innerHTML: indicates the text between tags.

Tag object. innerHTML = new data: assign values to the content between tags.

// Dialog box:

Alert (): A normal pop-up window

Confirm (): A confirmation and cancellation pop-up window is displayed.

Prompt (): pop-up with an input box

SetTimeout (func, n); // timer. After n seconds, execute the program in func, in milliseconds.

ClearTimeout (s); // cancels the timer effect. The parameter is the time Id generated by setTimeout.

SetInterval (func, n): executes a task at a fixed interval.

ClearInterval (s );

// String Conversion numeric parseInt ();

Var h upload document.doc umentElement. clientHeight; // get the height of the browser

Var w =document.doc umentElement. clientWidth; // obtain the browser width.

Var p1 = document. getElementById ("id"); // obtain the object of the tag whose ID is id

Iw = parseInt (w) // converts w to a numeric value.

Ih = parseInt (h)

P1.style. height = ih + 'px '; // value assignment

P1.style. width = iw + 'px ';

The above is all of the content in this article. I hope it will be helpful for you to use JavaScript labels and methods for future projects.

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.