1. Traditionally, string connection has always been one of the operations with the lowest performance in js. Var text = "Hello ";Text + = "World! ";Early browsers did not optimize this operation.Because the string is immutable, this means that you
When using JQuery, if you want to find a container (such as div or some sub-elements in table), you can easily use the find method. Find will search for all sub-elements that meet the conditions in an iterative way, and can set css and other content
1. determine whether an object existsIf the following jQuery code is used to determine whether an object exists, it cannot be used.If ($ ("# id ")){} Else {}Because $ ("# id") returns an object regardless of whether the object exists.Correct use:If (
Example $. cookie ('name', 'value ');Set the cookie value and set the value of the name variable to value.Example $. cookie ('name', 'value', {expires: 7, path: '/', domain: 'jquery. com', secure: true });Create a cookie, including the Domain Name
With this example, we hope that the content of example.html will be retrieved using the method of ajax, and then the div of the page id = callbackdemo3 will be dynamically updated.The HTML is as follows:Copy codeThe Code is as follows: ajax load1
There are two common methods to check the variable type:Method 1: typeofFormat: typeof variableUsage: if (typeof variable = "type identifier "){...}Below are some typeof values corresponding to common data types:{An: "object"}: object["An", "array"]:
Global variables are part of the properties of the Window object. For example:Copy codeThe Code is as follows:Var test = 'test ';Alert (window. test ); The general sequence of browser rendering and HTML operations:HTML parsing completedExternal
Copy codeThe Code is as follows:Function ReportFileStatus (filespec){Var fso, s = filespec;Fso = new ActiveXObject ("Scripting. FileSystemObject ");If (fso. FileExists (filespec ))S + = "exists .";ElseS + = "doesn' t exist .";Return (s );}Use the
Today, I practiced the following code for the Jquery fade-in and fade-out feature:Copy codeThe Code is as follows: untitled document CSS solution jQuery solution Images used:An example of Fade-in and fade-out is as follows:Copy codeThe Code is
Copy codeThe Code is as follows:Function f1 (){Var n = 999;NAdd = function () {n + = 1 ;}Function f2 (){Alert (n );}Return f2;} Here, the closure is f1, which closes a Variable n and a function f2.We will ignore nAdd and try to rewrite this function
Although this does not have any impact on the function, but the experience is always not very good, then how to solve this problem, there are many articles on the Internet that have said to set the window after being loaded by the target page.
Jquery. history. js plug-in to be usedOn the shoulders of giants, the following steps forward and backward are completed based on plug-ins!I worked on several part-time jobs and made an ajax request when I completed the page. When the browser is
All code
Copy codeThe Code is as follows:
/**
* @ Author xing
*/
(Function ($ ){
$. Extend ({
Alert: function (html, callback ){
Var dialog = new Dialog ();
Dialog. build ('alert ', callback, html );
},
Confirm: function (html, callback ){
Var
Event stream
The event stream in the browser means that there may be one or more elements on the page to respond to the same event. The order in which one or more elements respond to events varies with browsers (mainly for IE and Netscape.Dubbed
Today, I checked Sina's js Code and found a back-cast Advertising Code, which is good from both the learning and usage perspectives. But I found a problem that will be blocked.The following is the specific js Code.Copy codeThe Code is as
Copy codeThe Code is as follows:Function Flower (){This. name = "rose ";This. color = "red ";}// Flower () as the constructorVar obj = new Flower ();// Output true, flower as class referenceAlert (obj instanceof Flower );The function keyword can
Reducing the number of DOM can accelerate the construction of DOM Tree and render tree during page parsing by the browser, thus improving the page performance. For this reason, we can save the HTML that is invisible to the first screen rendering in
Method 1:Use a browser internal converter to implement conversion by dynamically creating a container label element, such as DIV, and setting the string to be converted to the innerText of this element (ie supported) | textContent (supported by
4. restrict direct DOM operationsThe basic idea here is to create what you really want in the memory and then update the DOM. This is not a jQuery best practice, but it must be used for effective JavaScript operations. Direct DOM operations are slow.
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