JS the way to execute a string as a function _javascript tips

Source: Internet
Author: User
and use JS to carry out:
<script language= "JavaScript" > Function Test (str) {alert (str); } window[' Test ' (' aaaaaaaaaaaaaaaaaaaaa '); </SCRIPT>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

-------------------------------
Method one ...
<script language= "JavaScript" > Function Test (str) {alert (str); Eval (' Test (' aaaaaaaaaaaaaaaaaaa ') '); </SCRIPT>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

This is method two ....
The function to be executed by the checkbox is set in the value of the checkbox, and the method parameter passes the currently clicked CheckBox as an argument.
Here I use the big jquery to manipulate
Copy Code code 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 ()///Get a string of functions to execute
var cc = $ck. Get (0);//Convert jquery object to DOM object
WINDOW[FF] (cc); The function that executes the string and passes the current CheckBox object as an argument
}
else {
$ck. attr ("Checked", "");
$ ("[name= ' ck ']:checkbox"). attr ("Checked", "");
var ff = $ck. val ();
var cc = $ck. Get (0);
WINDOW[FF] (cc);
}
}
else//as a choice.
{
if ($ck. attr ("checked") = = False) {
$ck. attr ("Checked", "checked");
var s = $ck. Val ();
var a = $ck. Get (0);
Window[s] (a);
}
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.