jQuery操作checkbox选择checked

代码:

复制代码
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html  xmlns = "http://www.w3.org/1999/xhtml" >
< head  runat = "server" >
     < title ></ title >
     < script  src = "Scripts/jquery-1.7.min.js"  type = "text/javascript" ></ script >
     < script  type = "text/javascript" >
         $(function () {
             // 全选
             $("#btnCheckAll").bind("click", function () {
                 $("[name = chkItem]:checkbox").attr("checked", true);
             });
 
             // 全不选
             $("#btnCheckNone").bind("click", function () {
                 $("[name = chkItem]:checkbox").attr("checked", false);
             });
 
             // 反选
             $("#btnCheckReverse").bind("click", function () {
                 $("[name = chkItem]:checkbox").each(function () {
                     $(this).attr("checked", !$(this).attr("checked"));
                 });
             });
 
             // 全不选
             $("#btnSubmit").bind("click", function () {
                 var result = new Array();
                 $("[name = chkItem]:checkbox").each(function () {
                     if ($(this).is(":checked")) {
                         result.push($(this).attr("value"));
                     }
                 });
 
                 alert(result.join(","));
             });
         });
     </ script >
</ head >
< body >
     < div >
         < input  name = "chkItem"  type = "checkbox"  value = "今日话题"  />今日话题
         < input  name = "chkItem"  type = "checkbox"  value = "视觉焦点"  />视觉焦点
         < input  name = "chkItem"  type = "checkbox"  value = "财经"  />财经
         < input  name = "chkItem"  type = "checkbox"  value = "汽车"  />汽车
         < input  name = "chkItem"  type = "checkbox"  value = "科技"  />科技
         < input  name = "chkItem"  type = "checkbox"  value = "房产"  />房产
         < input  name = "chkItem"  type = "checkbox"  value = "旅游"  />旅游
     </ div >
     < div >
         < input  id = "btnCheckAll"  type = "button"  value = "全选"  />
         < input  id = "btnCheckNone"  type = "button"  value = "全不选"  />
         < input  id = "btnCheckReverse"  type = "button"  value = "反选"  />
         < input  id = "btnSubmit"  type = "button"  value = "提交"  />
     </ div >
</ body >
</ html >
复制代码


//-------------------------------------tags----------------------------------------------------//
// 全选
$("#allid").bind("click", function () {
$("[name = id_list[]]:checkbox").attr("checked", true);
});

// 全不选
$("#allid2").bind("click", function () {
$("[name = id_list[]]:checkbox").attr("checked", false);
});

$("#form_up").submit(function(){
//alert($("[name = id_start]:input").val());
id_start = $("[name = id_start]:input").val();
id_over = $("[name = id_over]:input").val();
if(id_start)
{
if(isNaN(id_start))
{
alert('起始id 请填写正确的数字!');
return false;
}
}

if(id_over)
{
if(isNaN(id_over))
{
alert('结束id 请填写正确的数字!\n idfaaadsdsfaaf');
return false;
}
}

id_list_len = $("input[type='checkbox'][name='id_list[]']:checked").length;
if(id_list_len == 0 && !id_start && !id_over)
{
alert('请填写需要更新的id!');
return false;
}

var idall = "";//需要更新的id
if(id_list_len>0)
{
idall+='id: \n(';
$("input[type='checkbox'][name='id_list[]']:checked").each(function(){
idall+=$(this).val()+", ";
});
idall+=')';
//alert($(this).val());
}

if(id_start)
{
idall = idall+' \n 起始id '+id_start;
}
if(id_over)
{
idall = idall+' - 结束id '+id_over;
}

tags = $("input[type = 'text'][name = 'tags']").val();
idall = idall+' \n tags:'+tags;

if(confirm('确定批量更新吗? \n '+idall))
{
return true;
}
return false;
});

//-------------------------------------tags 结束----------------------------------------------------//


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值