jquery取选中的checkbox的值
一。 在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的值的更多相关文章
- Jquery获取选中的checkbox的值
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...
- jQuery 取选中的radio的值方法
var val=$('input:radio[name="sex"]:checked').val(); 附三种方法都可以: $('input:radio:checked').val ...
- jquery获取选中的文本和值
jquery获取选中的文本和值 1.说明 (1)获取select下拉框选中的索引 $("#selection").get(0).selectedIndex; (2)获取 ...
- jquery获取选中select的文本,值等
jquery获取select选择的文本与值获取select :获取select 选中的 text : $("#ddlregtype").find("option:s ...
- jquery 获取input radio/checkbox 的值 【注意写法】
今天,在用jquery获取页面上radio值的时候,radio给出了默认值,但是无论如何修改值,radio始终是默认值,去掉默认值的时候,页面上又报出了undefined的错误.经过几番搜索,发现不同 ...
- jquery获取多个checkbox的值异步提交给php
html代码: <tr> <td><input type="checkbox" name="uid" value="&l ...
- Repeater控件里面取不到CheckBox的值
然后在后台需要取到,选中了那些 然后在后台怎么取也取不到,当时就纳闷了,然后开始怀疑自己的代码是不是错了,经过仔细一看,我的妈呀,加载事件了差一句话......整个人都不好了 加载事件差这句话不行,补 ...
- JQuery判断checkbox选中,jquery获取选中的checkbox
选中的radio $('input[name="radInvoiceType"]:checked').val(); 这样能获得 $('input[name="radInv ...
- jquery 取的单选按钮组的值
<input type=”radio” name=”wholesale_one” id=”wholesale_one” value=”1″ />1箱起批<input type=”ra ...
随机推荐
- 走进 thrift server
thrift的使用介绍 thriftthrift clientthrift serverthrift 0.7.0 一.About thrift 二.什么是thrift,怎么工作? 三.Thri ...
- How To Add User To Sudoers On Debian 10 Buster
In today’s tutorial, we are going to see how you can add a user to sudoers on Debian distributions. ...
- greenplum(postgresql) 数据字典
greenplum是基于postgresql开发的分布式数据库,里面大部分的数据字典是一样的.我们在维护gp的时候对gp的数据字典比较熟悉,特此分享给大家.在这里不会详细介绍每个字典的内容,只会介绍常 ...
- Mokia 摩基亚
题目链接:[https://www.luogu.com.cn/problem/P4390] 快捷版题意: 维护一个\(W*W\)的矩阵,初始值均为\(S\).每次操作可以增加某格子的权值,或询问某子矩 ...
- 自定义starter
https://github.com/deadzq/spring-boot-starter-hello 父子项目 子项目引用父项目中的依赖和配置参数
- testdisk修复磁盘文件
使用testdisk,分析之后,使用:P ,list文件,然后使用如下方法恢复文件 Use Right to change directory, h to hide Alternate Data St ...
- 简述*args and **kwargs
为了能让一个函数接受任意数量的位置参数:* 为了接受任意数量的关键字参数:** *参数只能出现在函数定义中最后一个位置参数后面,而**参数只能出现在最后一个参数 解决的问题:构造一个可接受任意数量参数 ...
- Tkinter 之Scale滑块标签
一.参数说明 语法 作用 Scale(window, label="滑块") 滑块标题 Scale(window, label="滑块", from_=0) 滑 ...
- arcgis python 表属性转html
import arcpy import sys import string import os tablePath = arcpy.GetParameterAsText(0) filePath = a ...
- Flutter移动电商实战 --(42)详细页_UI主页面架构搭建
详细分成六大部分拆分开 body里面用FutureBuilder异步加载. FutureBuilder里面的furure属性这里用一个方法,必须返回的也是future 把我们的方法修改为返回的类型为F ...