jquery checkbox radio

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();



   



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值