jquery操作checkbox或radio
2017-03-19 16:22
477 查看
一.复选框操作
1.1 首先看html代码
<div id="box">
<input type="checkbox" id="chk1" checked />chk1
<input type="checkbox" id="chk2" checked />chk2
<input type="checkbox" id="chk3" />chk3
<input type="checkbox" id="chk4" />chk4
</div>
1.2 操作checkbox的js代码
二、单选框操作
2.1 首相看html代码
<div id="box">
<input type="radio" id="rad1" checked /> rad1
<input type="radio" id="rad2" checked /> rad2
<input type="radio" id="rad3" /> rad3
<input type="radio" id="rad4" /> rad4
</div>
2.2操作radio的js代码
//单选框操作
//查找所有单选框
console.log($(":radio"));
//查找所有选中的单选框
console.log($(":radio").filter(":checked"));
//查找所有未选中的单选框
console.log($(":radio").not(":checked"));
//判断单选框是否被选中
console.log($("#rad1").is(":checked"));
//选中单选框
$("#rad3").prop("checked","checked");
//取消单选框选择
$("#rad1").removeAttr("checked");
1.1 首先看html代码
<div id="box">
<input type="checkbox" id="chk1" checked />chk1
<input type="checkbox" id="chk2" checked />chk2
<input type="checkbox" id="chk3" />chk3
<input type="checkbox" id="chk4" />chk4
</div>
1.2 操作checkbox的js代码
//复选框操作 //查找所有复选框 console.log($(":checkbox")); console.log($("#box").find(":checkbox")); //查找所有选中的复选框 console.log($(":checked")); //查找所有未选中的复选框 console.log($(":checkbox:not(:checked)")); //判断复选框是否被选中 console.log($("#chk1").is(":checked")); //选中复选框 $("#chk3").prop("checked","checked");//注意1.4.4版本不支持prop方法 //取消选择复选框 $("#chk1").removeAttr("checked");
二、单选框操作
2.1 首相看html代码
<div id="box">
<input type="radio" id="rad1" checked /> rad1
<input type="radio" id="rad2" checked /> rad2
<input type="radio" id="rad3" /> rad3
<input type="radio" id="rad4" /> rad4
</div>
2.2操作radio的js代码
//单选框操作
//查找所有单选框
console.log($(":radio"));
//查找所有选中的单选框
console.log($(":radio").filter(":checked"));
//查找所有未选中的单选框
console.log($(":radio").not(":checked"));
//判断单选框是否被选中
console.log($("#rad1").is(":checked"));
//选中单选框
$("#rad3").prop("checked","checked");
//取消单选框选择
$("#rad1").removeAttr("checked");
相关文章推荐
- jQuery的radio,checkbox,select操作
- jQuery的radio,checkbox,select操作
- JQuery操作Select,CheckBox,Radio
- jquery操作表单,包括常用的radio,checkbox,select
- jQuery的radio,checkbox,select操作
- jQuery的radio,checkbox,select操作
- jQuery操作 checkbox 的全选、反选 , radio, select 功能
- jquery实用应用之jquery操作radio、checkbox、select选中
- [转]JQuery操作checkbox、radio等示例
- jQuery操作 checkbox 的全选、反选 , radio, select 功能
- JQuery操作checkbox、radio
- Jquery操作radio,checkbox,select表单操作实现代码
- jquery对text/radio/checkbox/select/areatext的操作
- jQuery操作select,radio,checkbox
- JQuery 操作select checkbox radio
- [转贴]jQuery的radio,checkbox,select操作 - [jQuery]
- jquery取得text,areatext,radio,checkbox,select的值,以及其他一些操作[转]
- jquery下的 radio,checkbox,select操作
- jQuery操作radio,checkbox,select
- jQuery操作radio,checkbox,select