一。   在html的checkbox里,选中的话会有属性checked="checked"。

如果用一个checkbox被选中,alert这个checkbox的属性"checked"的值alert($"#xxx".attr("checked")),会打印出"true",而不是"checked"!

如果没被选中,打印出的是"undefined"。觉得很奇怪是吗?继续看下去~

不要尝试去做这样的判断:if($"#xxx".attr("checked")=="true")   //这样是错误的

因为这么做是错的,jQuery的API手册上写,attr(name)的返回值是object。所以,应该是   if($("#xxx").attr("checked")==true)。

判断这个值 $("input[name='weibo_count']").attr("checked");  这样也行

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<SCRIPT LANGUAGE="JavaScript">
  <!--
   $("document").ready(function(){
    
    $("#btn1").click(function(){
     
    $("[name='checkbox']").attr("checked",'true');//全选
  
    })
       $("#btn2").click(function(){
     
    $("[name='checkbox']").removeAttr("checked");//取消全选
  
    })
    $("#btn3").click(function(){
     
    $("[name='checkbox']:even").attr("checked",'true');//选中所有奇数
  
    })
    $("#btn4").click(function(){
     
    $("[name='checkbox']").each(function(){
     
   
     if($(this).attr("checked"))
   {
    $(this).removeAttr("checked");
    
   }
   else
   {
    $(this).attr("checked",'true');
    
   }
   
    })
  
    })
     $("#btn5").click(function(){
       var checks = "";
    $("input[name='checkbox[]']").each(function(){
        if($(this).attr("checked") == true){
            checks += $(this).val() + "|";            //动态拼取选中的checkbox的值,用“|”符号分隔
        }
    })
   })
  //-->
  </SCRIPT>
  
 </HEAD>
 <BODY>
 <form name="form1" method="post" action="">
   <input type="button" id="btn1" value="全选">
   <input type="button" id="btn2" value="取消全选">
   <input type="button" id="btn3" value="选中所有奇数">
   <input type="button" id="btn4" value="反选">
   <input type="button" id="btn5" value="获得选中的所有值">
   <br>
   <input type="checkbox" name="checkbox[]" value="checkbox1">
   checkbox1
   <input type="checkbox" name="checkbox[]" value="checkbox2">
   checkbox2
   <input type="checkbox" name="checkbox[]" value="checkbox3">
   checkbox3
   <input type="checkbox" name="checkbox[]" value="checkbox4">
   checkbox4
 </form>
</body>
</html>

jquery取选中的checkbox的值的更多相关文章

  1. Jquery获取选中的checkbox的值

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  2. jQuery 取选中的radio的值方法

    var val=$('input:radio[name="sex"]:checked').val(); 附三种方法都可以: $('input:radio:checked').val ...

  3. jquery获取选中的文本和值

    jquery获取选中的文本和值 1.说明 (1)获取select下拉框选中的索引       $("#selection").get(0).selectedIndex; (2)获取 ...

  4. jquery获取选中select的文本,值等

    jquery获取select选择的文本与值获取select :获取select 选中的 text :    $("#ddlregtype").find("option:s ...

  5. jquery 获取input radio/checkbox 的值 【注意写法】

    今天,在用jquery获取页面上radio值的时候,radio给出了默认值,但是无论如何修改值,radio始终是默认值,去掉默认值的时候,页面上又报出了undefined的错误.经过几番搜索,发现不同 ...

  6. jquery获取多个checkbox的值异步提交给php

    html代码: <tr> <td><input type="checkbox" name="uid" value="&l ...

  7. Repeater控件里面取不到CheckBox的值

    然后在后台需要取到,选中了那些 然后在后台怎么取也取不到,当时就纳闷了,然后开始怀疑自己的代码是不是错了,经过仔细一看,我的妈呀,加载事件了差一句话......整个人都不好了 加载事件差这句话不行,补 ...

  8. JQuery判断checkbox选中,jquery获取选中的checkbox

    选中的radio $('input[name="radInvoiceType"]:checked').val(); 这样能获得 $('input[name="radInv ...

  9. jquery 取的单选按钮组的值

    <input type=”radio” name=”wholesale_one” id=”wholesale_one” value=”1″ />1箱起批<input type=”ra ...

随机推荐

  1. python - pycharm 配置虚拟环境出现的中文命名问题

    说一个困扰我很久的问题,当使用 pycharm 配置新的虚拟环境想要与之前的环境隔离的时候,正常的点击 New Project 创建项目时,不勾选 Inherit global site-packag ...

  2. Promise.then方法的执行顺序例题分析

    1. 当Promise对象作为resolve的参数时 const p = Promise.resolve(); const p1 = Promise.resolve(p); //就是p const p ...

  3. HTML5中table标签与form标签的区别

    html中form表示一个表单,用来把一系列的控件包围起来,然后再统一发送这些数据到目标,比如最常见的注册,你说需要填写的资料,都是被封装在form里的,填写完毕后,提交form内的内容,如果不再fo ...

  4. bzoj 3999: [TJOI2015]旅游 LCT

    没啥难的,inf 的值设小了调了半天~ code: #include <bits/stdc++.h> #define N 50003 #define lson t[x].ch[0] #de ...

  5. leetcode解题报告(22):Two Sum II - Input array is sorted

    描述 Given an array of integers that is already sorted in ascending order, find two numbers such that ...

  6. 【csp模拟赛九】--dfs

    思路: 这道题可以宽搜,深搜,最短路 代码: #include<cstdio> #include<cstring> #include<iostream> #incl ...

  7. Java 【打印俄文的英文字母】

    俄文的的字符可以用 'A' 到 'Я '. public class main { public static void main(String args[]) { char S = 'А', C = ...

  8. 带着历史提交记录迁移git仓库

    1. git push --mirror --mirror模式会把本地的分支都克隆 // 先用--bare克隆裸仓库 git clone git@gitee.com:zhangamie/testApp ...

  9. As I Began to Love Myself

    As I Began to Love Myself: Charlie Chaplin on his 70th birthday As I began to love myself I found th ...

  10. java中int 和String相互转换

    一.String转为int int i=Integer.parseInt(string):int i=Integer.valueOf(s).intValue(); 二.int转为String Stri ...