JS treats strings as function execution methods

Source: Internet
Author: User

And use js to execute: <textarea id="runcode32729"></textarea>
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]

-------------------------------
Method 1...
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]

This is method 2 ....
The function to be executed is set in the value of the checkbox, and the method parameter is to pass the checkbox currently clicked as the parameter.
Here I use large jquery for operationsCopyCode The Code is as follows: $ (function (){
$ ("Ul Li a" ).css ("cursor", "Pointer ");
$ ("Ul Li a"). Click (function (){
VaR $ ck = $ (this). siblings (": checkbox ");
If ($ CK. ATTR ("name") = "Total") // select all
{
If ($ CK. ATTR ("checked") = false ){
$ CK. ATTR ("checked", "checked ");
$ ("[Name = 'ck ']: checkbox"). ATTR ("checked", "checked ");
VaR FF = $ CK. Val (); // gets the string of the function to be executed
VaR cc = $ CK. Get (0); // converts a jquery object to a DOM object.
Window [ff] (CC); // execute the string function and pass the current checkbox object as a parameter
}
Else {
$ CK. ATTR ("checked ","");
$ ("[Name = 'ck ']: checkbox"). ATTR ("checked ","");
VaR FF = $ CK. Val ();
VaR cc = $ CK. Get (0 );
Window [ff] (CC );
}
}
Else // select one
{
If ($ CK. ATTR ("checked") = false ){
$ CK. ATTR ("checked", "checked ");
VaR S = $ CK. Val ();
VaR A = $ CK. Get (0 );
Window [s] ();
}
Else {
$ CK. ATTR ("checked ","");
VaR S = $ CK. Val ();
VaR cb = $ CK. Get (0 );
Window [s] (CB );
}
}
})
})

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.