There are two common methods to check the variable type:
Method 1: typeof
Format: typeof variable
Usage: If (typeof variable = "type identifier "){...}
Below are some typeof values corresponding to common data types:
{An: "object"}: Object
In JavaScript, the scope of variables is defined by functions. variables are valid within a function range. For example:
CopyCodeThe Code is as follows: var F = false;
If (true) {var F = true;} // at this time, F is located within the if, that is,
1. Hidden elements cannot obtain the focus.
2. Obtain the focus for div and other special elements
Xmlns = "http://www.w3.org/1999/xhtml">
Focus on Element Acquisition: 1. Hidden elements cannot obtain focus.
There is a hidden input below:
The document. getelementsbyname (name) method is used to read the object array. The usage is as follows:
VaR elements = Document. getelementsbyname ("role ");
("Role" is the name of each checkbox in the checkbox array)
For:
select a role
DEMO code:
footfall www.jb51.net foothome www.jb51.net foothome www.jb51.net Home of feet www.jb51.net
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Core
When writing a program, you often need to remove repeated elements from the array. It is not difficult to implement this function.
We can implement it with a two-repeating loop. For small arrays, this is certainly not inappropriate.
However, if our
MyDate. getYear (); // obtain the current year (2 digits)
MyDate. getFullYear (); // obtain the complete year (4 bits, 1970 -????)
MyDate. getMonth (); // obtain the current month (0-11, 0 represents January)
MyDate. getDate (); // obtain the
We recommend that you use encodeURIComponent (), GET, and POST to send the URL encoding of variable values.
There are several methods in JavaScript to encode URL strings: escape (), encodeURI (), and encodeURIComponent (). These encodings play
For example, if it is 14 characters, 14 characters can be entered before the user input). When the user starts to input data, * is replaced in sequence, enter a few characters and replace them with a few characters. After the input, only the
Copy codeCode: var lishustr = "qwertyuiopasdfghjklmnbvcxz ";
Var s = lishustr. split ("");
Var lishua = ""; var lishub = ""; var lishuc = ""; var lishud = "";
Lishua = s [getRandomNum ()]; lishub = s [getRandomNum ()]; lishuc = s [getRandomNum ()];
The correct source code is as follows:
Copy codeThe Code is as follows:
I define var btnReg = document. getElementById ("btnReg") in the fourth line as the global variable btnReg = document. getElementById ("btnReg ");Besides the function abc (),
Use JavaScript to calculate the number of images loaded.
Principle:
Define An image array first, and then calculate it through the onload event of the image. Note that onload is different from Firefox in ie.
Finally, you need to combine a progress
Three methods for creating an object
Method 1:
Copy codeThe Code is as follows: var obj = new Object ();
Obj. Property = value;
// Continue adding other attributes
Obj. method = function (parameter ){
// Function Code
}
// Continue adding
Copy codeThe Code is as follows :/*
* JavaScript objects are a set of attributes (methods ).
* If the variable or method name does not comply with the Declaration Rules in this language,
* You must reference it with square brackets [].
*
*/
/**
*
Copy codeThe Code is as follows: var test = (function () {var arr2 = [1, 2, 3]; return function () {return arr2 ;};})()
Array. prototype. f1 = function () {return [];}
Array. prototype. f2 = function () {this. length = 0; return this ;}
Then you
1. Delay switching tabRequirement: There are several tabs on the page. When you switch to a tab, the data in a specific area is pulled and updated.
Disadvantage: You can quickly switch from the first tab to the end, and then generate n ajax
Fixed the hashtableobj. set ("length", "0") bug.
You can set the key to ignore the case sensitivity.
Clone hashtable objects
You can use obj. valueOf ("key", "defalutvalue") to set the default value.
Bug fixes
Copy codeThe Code is as follows:
But from the global perspective, this will lead to some situations that make us unable to control: the variable with the same name, the transformation of the value after multiple functions share a global variable ...... And so on. So sometimes, for
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