Home > Web Front-end > JS Tutorial > body text

js method to execute string as function_javascript skills

WBOY
Release: 2016-05-16 18:31:54
Original
1314 people have browsed it

And use js to execute:


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

------ --------------------------
Method 1. . .

[Ctrl A Select All Note:
If you need to introduce external Js, you need to refresh to execute
]

This is method two. . . .
The function to be executed by the checkbox is set in the value of the checkbox, and the parameter of the method is to pass the currently clicked checkbox as a parameter.
Here I use jquery to operateCopy code
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();//Get the string of the function to be executed
var cc = $ck.get(0);// Convert jquery Convert the 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//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);
}
}
})
})
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template