jquery获取checkbox的值
<div class="form-group"> <label class="col-md-3 control-label">职务</label> <div class="col-md-9"> <foreach name="arr2" item="v" > <div class="checkbox"> <label> <input type="checkbox"<?php foreach($arr as $kk=>$vv){ foreach($vv['role_name'] as $ko=>$vo){ if($vo==$v['role_name']){ echo "checked"; } } } ?> name="checkbox" value="{$v.r_id}"> {$v.role_name} </label> </div> </foreach> </div> </div>
jquery代码:
<script> $("#sub").click(function () { var username = $("#username").val(); var spCodesTemp = ""; $('input:checkbox[name="checkbox"]:checked').each(function(i){ if(0==i){ spCodesTemp = $(this).val(); }else{ spCodesTemp += (","+$(this).val()); } }); alert(spCodesTemp); }); </script>
这其中的 [name="checkbox"] 引号里代表的就是name的值
通往牛逼的路上,在意的只有远方!