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

Comprehensive JS checkbox for selecting all, deselecting all, and deleting function codes_javascript skills

WBOY
Release: 2016-05-16 18:57:40
Original
1059 people have browsed it

看下面两种实现方法:
JS checkbox 方法一:

复制代码 代码如下:

function checkAll()
{
var code_Values = document.all['code_Value'];
if(code_Values.length){
for(var i=0;i{
code_Values[i].checked = true;
}
}else{
code_Values.checked = true;
}
}
function uncheckAll()
{
var code_Values = document.all['code_Value'];
if(code_Values.length){
for(var i=0;i{
code_Values[i].checked = false;
}
}else{
code_Values.checked = false;
}
}
function multipleDelete()
{
var num = 0;
var code_Values = document.all['code_Value'];
if(code_Values.length){
for(var i=0;i{
if(code_Values[i].checked == true)
{
num ;
}
}
}else{
if(code_Values.checked == true){
num ;
}
}
if(num == 0){
alert('Please select delete item');
}
if(num >0){
document.BuCodeSearch.action = '<%=EusUtil.getPage("lookup.generic.bucode.delete.s")%>';
document.BuCodeSearch.submit();
}
}


JS checkbox方法二:
复制代码 代码如下:

function checkAll()
{
var code_Values = document.getElementsByTagName("input");
for(i = 0;i < code_Values.length;i ){
if(code_Values[i].type == "checkbox")
{
code_Values[i].checked = true;
}
}
}
function uncheckAll()
{
var code_Values = document.getElementsByTagName("input");
for(i = 0;i < code_Values.length;i ){
if(code_Values[i].type == "checkbox")
{
code_Values[i].checked = false;
}
}
}
function multipleDelete()
{
if (document.BuCodeSearch.elements["code_Value"])
{
var num = 0;
var fm = document.BuCodeSearch;
if (document.BuCodeSearch.elements["code_Value"])
{
var elm = document.BuCodeSearch.elements["code_Value"];
var ename = "code_Value";
if (elm.length) {
var len = fm.elements[ename].length;
for (var i = 0; i< len; i ) {
var e = fm.elements[ename][i];
if (e.checked == true){
num ;
}
}
} else {
if (elm.checked == true ) {
num ;
}
}
if (num > 0 )
{
document.BuCodeSearch.action = '<%=EusUtil.getPage("lookup.generic.bucode.delete.s")%>';
document.BuCodeSearch.submit();
}
}
}
}

code_Value为checkbox表单的名称,BuCodeSearch为form名称
复制代码 代码如下:


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!