您的位置:首页 > Web前端 > JQuery

jquery 获取所有选中的多选按钮的值,附:获取未选中的所有多选按钮的值

2016-08-05 14:34 337 查看
html代码

<form class="myform">
<table>
<tr>
<td style="width: 80px;">
<input type="checkbox" id="category-49" name="playaudio" value="49">
<a style="font-size:18px;">营销</a>
</td>
<td style="width: 80px;">
<input type="checkbox" id="category-86" name="playaudio" value="86">
<a style="font-size:18px;">投资</a>
</td>
<td style="width: 80px;">
<input type="checkbox" id="category-50" name="playaudio" value="50">
<a style="font-size:18px;">职场</a>
</td>
<td style="width: 80px;">
<input type="checkbox" id="category-51" name="playaudio" value="51">
<a style="font-size:18px;">汽车</a>
</td>
<td style="width: 80px;">
<input type="checkbox" id="category-62" name="playaudio" value="62">
<a style="font-size:18px;">地产</a>
</td>
</tr>
</table>
</form>
<a href="javascript:;" onclick="ajaxClick(this)" name="" class="btn bgGreen opEditCate ">更新</a>


js代码 部分
function ajaxClick(){
var categoryList = "";
$('input:checkbox[name=playaudio]:checked').each(function(i){
if(0==i){
categoryList = $(this).val();
}else{
categoryList += (","+$(this).val());
}
});
alert(categoryList);
}

将选中的依次循环添加到 categoryList中,最终结果是逗号分开的字符串。使用起来也方便些。

获取所有未选中的多选按钮的值

$("input[name='playaudio']").not("input:checked");


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  html jquery php js