获取input type=radio属性的value值

 

个人代码1:

<div class="form-group" style=" 250px;margin:0 auto;">

<label for="">性别</label>

<input type="radio" id="driverSex" name="driverSex" value=""/>

<input type="radio" id="driverSex" name="driverSex" value=""/>

</div>

注意: 1.value属性不要写错,写错或没写会获取的值默认是on

    2.name 属性必须一致

 

个人代码2:

//编辑

     function editdriver(id) {

        $.ajax({

            url:"${pageContext.request.contextPath}/upadatedriver",

            type:"GET",

            data:{"id":id},

            success:function(result){

                console.log(result);

                $("input[name=driverSex]").val([result.driverSex]);//回显性别

            }

        });

        

         $("#driver").modal("show");//打开模态框

    }

 

其他参考:

1.获取选中值,三种方法都可以:
$('input:radio:checked').val();
$("input[type='radio']:checked").val();
$("input[name='rd']:checked").val();
2.设置第一个Radio为选中值:
$('input:radio:first').attr('checked', 'checked');
或者
$('input:radio:first').attr('checked', 'true');
注:attr("checked",'checked')= attr("checked", 'true')= attr("checked", true)
3.设置最后一个Radio为选中值:
$('input:radio:last').attr('checked', 'checked');
或者
$('input:radio:last').attr('checked', 'true');
4.根据索引值设置任意一个radio为选中值:
$('input:radio').eq(索引值).attr('checked', 'true');索引值=0,1,2....

好看的皮囊千篇一律,有味的文章百里挑一, 若你觉得好味,可以给个赞,

尊重原创,支持原创,转载博主的文章, 请务必标明作者和出处,谢谢 !

作者:Newbe落花

出处:https://www.cnblogs.com/fby698/

原文地址:https://www.cnblogs.com/fby698/p/9978194.html