首页 > 代码库 > jquery取选中的checkbox的值
jquery取选中的checkbox的值
一。
不要尝试去做这样的判断: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=http://www.mamicode.com/"全选">
<input type="button" id="btn2" value=http://www.mamicode.com/"取消全选">
<input type="button" id="btn3" value=http://www.mamicode.com/"选中所有奇数">
<input type="button" id="btn4" value=http://www.mamicode.com/"反选">
<input type="button" id="btn5" value=http://www.mamicode.com/"获得选中的所有值">
<br>
<input type="checkbox" name="checkbox[]" value=http://www.mamicode.com/"checkbox1">
checkbox1
<input type="checkbox" name="checkbox[]" value=http://www.mamicode.com/"checkbox2">
checkbox2
<input type="checkbox" name="checkbox[]" value=http://www.mamicode.com/"checkbox3">
checkbox3
<input type="checkbox" name="checkbox[]" value=http://www.mamicode.com/"checkbox4">
checkbox4
</form>
</body>
</html>
<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=http://www.mamicode.com/"全选">
<input type="button" id="btn2" value=http://www.mamicode.com/"取消全选">
<input type="button" id="btn3" value=http://www.mamicode.com/"选中所有奇数">
<input type="button" id="btn4" value=http://www.mamicode.com/"反选">
<input type="button" id="btn5" value=http://www.mamicode.com/"获得选中的所有值">
<br>
<input type="checkbox" name="checkbox[]" value=http://www.mamicode.com/"checkbox1">
checkbox1
<input type="checkbox" name="checkbox[]" value=http://www.mamicode.com/"checkbox2">
checkbox2
<input type="checkbox" name="checkbox[]" value=http://www.mamicode.com/"checkbox3">
checkbox3
<input type="checkbox" name="checkbox[]" value=http://www.mamicode.com/"checkbox4">
checkbox4
</form>
</body>
</html>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。