You need to know some tips in JS (DHTML) _ basic knowledge

Source: Internet
Author: User
Tags cdata
You need to know some tips in JS (DHTML) that haven't updated the log these days. This article is just a bit of my own experience. I would like to give you some tips. If you have any questions, please leave a message below.

I. Equality Operators
In JS, the numbers not 0 are all true, except for a few special variables. For example, undefined, null, and. This is what we expect in most cases.
However, you should not ignore this full equality operator. Therefore, we need to strictly verify this. We can use the = full equality operator to view the following code:
// Some common verification results
Var foo = function (arg ){
If (! Arg ){
Alert ("normal false ");
} Else {alert ("true ");}
}
Foo (null); // false
Foo (false); // false
Foo (""); // false
Foo ("never-online"); // true
// Full equivalent Verification
Var foo = function (arg ){
If (arg = false ){
Alert ("false ");
} Else {alert ("not a false variable ")}
}
Foo (null); // not a false variable
Foo (false); // false
Foo (""); // not a false variable
Foo ("never-online"); // not a false variable

2. Application of Variable -- Remove Web page nesting
For example, if you want to embed baidu.com into your own iframe, the result is not what you want, because it has such a code
If (self! = Top) {top. location = self. location ;}
This Code indicates that if a webpage is nested (that is, frame technology is used, nesting is removed and the url in the frame is given to the top-level window)
This is a headache. For example, the above Code is also used in some free space. What if it is removed? With this code, nesting can be removed:
Script
Var location = 'Never-online ';
Script
The following describes why this code can be used to remove nesting:
We know that in JS variables, if the variables are like this
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.