js选中复选框,选中单选框,checkbox选中,反选,全选,radio选中

我来纠错
//设置选中复选框、单选框
$('.input').attr('checked','checked');

//设置取消选中复选框、单选框
$('.input').removeAttr('checked');

//设置checkbox反选
<input class="input" type="checkbox">
<div class="btn">选中复选框</div>

$(document).on('click','.btn',function(e){
	//检测每一个复选框的选中状态,对其反选
	$('.input').each(function(index) {
		var $this = $(this);
		//判断选中状态
		if ($this.attr('checked')) {
			$this.removeAttr('checked');
		}else{
			$this.attr('checked','checked');
		};
		
	});
});

//选中单选框,设置第三个单选框选中。
$('.input').eq(2).attr('checked','checked');
发送
热门关键词:
命令
知识类型:
标题描述:
详细解答:

提交审核您编辑的知识会经过 前端大牛 人工审核。