选取所有的表单元素

:input:所有表单元素

:text:获得所有text元素的元素,如要获得所有值,必须有each循环获得

:password:获得属性为password的元素

:checkbox:获得所有checkbox元素的元素,如要获得选中的值,则需要用each循环获得(:checkbox:checked)

http://www.cnblogs.com/yongwuqing/p/4251711.html

jquery获取复选框的值

$(":input[name='items']").attr('checked',true)// 全选
$("[name='items']").attr('checked',false)或者    //全不选
$("[name='checkbox']").removeAttr("checked");

  $("[name='checkbox']:even").attr("checked",'true');//选中所有奇数  
  1. $("[name='checkbox']").each(function(){        //反选一  
  2. if($(this).attr("checked")){  
  3.    $(this).removeAttr("checked");  
  4. }  
  5. else{  
  6.     $(this).attr("checked",'true');  
  7. }  
  8. })  

$("[name='items']").each(function(){                  //反选二
//$(this).attr('checked',!$(this).attr('checked'))
this.checked = !this.checked;
})
 $('#checkSel').click(function(){          //全选/全不选

console.log(this.checked)
/*            if(this.checked){
$("[name='items']").attr('checked',true)
}else{
$("[name='items']").attr('checked',false)

}*/
$("[name='items']").attr('checked',this.checked)
})
//输出选中的值
$("[name='items']:checked").each(function(){
var str=$(this).val()
$('.checkBox').append(str)
})
 
 

 

 

 





posted on 2017-03-02 17:19  懒人猫  阅读(268)  评论(0)    收藏  举报