JS Summary Experience

Source: Internet
Author: User
Tags script tag

1, after the form element is committed (not refreshed) the data will still exist, want to submit after the purge data can be submitted after AJAX data, with the Reset () method to clear the data.

2, JS How to determine which radio control is selected, that is, the form control is selected which properties have changed.

When the form is submitted to the background, the selected input will pass the value in its own Value property to the background. As for the front-end JS How to judge also need to study. The Value property is used differently for different input types (see also novice net)

3, if the new version of the jquery Toggle () method Obsolete, you need to encapsulate one.

4, JS event is best to use the binding event (JQ with BIND () to bind the event) to add the event, if a request to click on a button, the element of the event needs to lock (point not moving), this time need to dismiss the event. Instead, only events bound with the Bind event bind can unbind the event.

5, JQuery 2.0 after the version is not supported IE6, 7, 8. It's best to use jquery version 1.9 and 1.8.

6, window.location.href= ". /xx.html ", this relative address is relative to the HTML. (This one is not the same as the others, be aware of it)

7, JSON object (JSON object 's property name must be enclosed in double quotation marks at any time , JSON object This is a data format, not a JS object instance) and JS object (JS object name is a string, so The JSON-formatted JavaScript object resembles the JSON object, and it begins to say that it is each other. Note the difference, as well as the JSON string (the whole is a string)

JSON is a data format, so there is no concept of variables. There are three JSON data formats: Simple, JSON object, JSON array

8, JS Once an error occurs, the following code will not be executed again. So the JS file is best not to write all in an external file, otherwise this JS once error, all references to this file page, will be executed to this error location, do not execute the following program.

Solution: 1, as far as possible, do not, all the methods put in a JS file.

2, the function and method as far as possible to release, that is, modular.

3, in already read and write good words, put the error JS code to the last execution, it does not affect the correct JS code in front of the line. Re-use of the JS code, can only be encapsulated in a file, or sub-function to generate different JS files.

4, the method, the function can be encapsulated in the same file, leaving a different interface, but will not execute, in their own pages to invoke the required method or function.

9, in order to prevent the application of a JS file is referenced by the HTML file execution, resulting in a program error, JS file program is best to different HTML programs to set different entry functions. This does not need the JS code will not be quoted, thus avoiding the JS.

Theself-executing function is the closure function, and the variable declared inside the closure function is not taken outside the function. With the closure feature, there is a return function inside the closure function, you can do the variable declaration within a function only once, but the callback function can be executed multiple times.

such as:var add = (function () {

var counter = 0;

return function () {return counter + = 1;}

})();

The dad () function can be executed many times, but var counter = 0; just once.

One, lazy loading is a performance-optimized approach: not special effects technology, but you can also make special effects (this effect once loaded, there is no effect). Principle: That is, when the element (piece) distance from the viewport when the image path inside the data, put in the SRC attribute inside the load element (image). Lazy loading is mainly used in the picture, because the picture data is relatively large. As for the video and music should also be OK. There are three implementation methods, the timer method, the event trigger loading, the visual area loading

Anassociative array is an object that is an attribute of an array, and the length of the printed array is not an associative array, and the level associative array is the property of the array object but not the element of the array.

all of the functions written in the JS file are encapsulated in a function, so that the page introduces JS files, but does not execute the JS program. Only the JS function that is called in the script tag in the Web page executes the function.

JS Summary Experience

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.