checkbox 复选框
radio 单选框 一组input name属性要相同
常用的功能
1:获取当前是否选中的状态
2:选中,不选中的操作
3:监听事件
1:得到dom对象
可以通过id选择器,类选择器,标签选择器和属性选择器得到dom对象,通过标签属性选择器如下:
<input type="checkbox" name="someBox" value="1" checked="checked" />
<input type="checkbox" name="someBox" value="2" />
JQuery:
$("input[name='someBox']").click(function(){});
2:操作dom对象
//设置选中
$('#id').attr("checked","checked");
//得到状态 true or false
$('#id').is(':checked');
//得到该dom的其他状态 value 为属性值
$('#id').attr('value');
//监听事件
$("input[name='markingMethods']").change(function(){
//操作
});
Radio
<input class="radio_style" id="forYear" type="radio" name="khzq" value="4"><label
for="forYear">年度</label>
<input class="radio_style" id="forHalfYear" type="radio" name="khzq" value="2" ><label
for="forHalfYear">半年度</label>
<input class="radio_style" id="forSeason" type="radio" name="khzq" value="1"><label
for="forSeason">季度</label>
<input class="radio_style" id="forMonth" type="radio" name="khzq" value="0"><label
for="forMonth">月度</label>
操作
//通过id选择器选中 和checkbox一致
$("#forMonth").attr("checked","checked");
//得到被选中radio
$('input:radio[name="khzq"]:checked').val();