Basic Analysis of js writing _ javascript tips-js tutorial

Source: Internet
Author: User
For more information about js writing, see. Var a = false;
! A & alert ("hi ");
If a is interpreted as true, the execution will continue, so hi will pop up.
Var a = a | "hi ";
This explains that when a is false, it will continue to be executed. When a is true, it will jump out of this statement, so we can copy the default value through this method.
Not all languages use this method, such as PHP.
$ A = @ $ a | "hi ";
Echo $ a; // 1
Php assigns a value after (@ $ a | "hi...
$ A = true;
! $ A & echo "hi ";
Direct error: syntax error, unexpected T_ECHO
About prototype
In many cases, we can see that prototype only has objects.
Var add = function () {alert ("B ");}
Add. prototype. a = function () {alert ("hi ");}
New add. prototype.;
First, an error may be reported. Otherwise, when no production object exists, you can directly call the static method by adding. prototype..
JS is misleading.
Selector problems:
Sometimes you need to select a subnode under a node and use childNodes to set the value to FIREFOX. The difference in IE is depressing.
Document. getElementsByTagName ("head") [0]. getElementsByTagName ("script") [0];
The results of the above method are used in the head label phase, but not very useful for other methods.
I think it is better to use a class name.

The Code is as follows:


Function getclassnode (classname, doc ){
Doc = doc | document;
Var node = [], I = 0, j = 0, t;
Var allnode = doc. getElementsByTagName ("*");
While (t = allnode [I]) {
If (RegExp (classname). test (t. className )){
Node [j] = t;
J ++;
}
I ++;
}
Return node;
}


After using JQ, I forgot about all the native JS operations. I occasionally reviewed it and felt very troublesome and depressing.
Make up a note of the JS found today. If a JS has been introduced to the current document, even if the introduced node is removed, the variables and functions defined by the JS file are still valid, because the file has been loaded to the current file environment, the following code:

The Code is as follows:


Document. getElementsByTagName ("head") [0]. removeChild (document. getElementsByTagName ("head") [0]. getElementsByTagName ("script") [0]);

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.