Jquery操作Input之Select和Radio选中

来源:互联网 发布:部门信息表sql 编辑:程序博客网 时间:2024/06/07 11:35

Select:

<div class="form-group"><label for="" class="col-sm-3 control-label">角色类型</label>    <div class="col-sm-9">        <select id="typeId" name="role_type" datatype="*">        <option value="1">公用</option>        <option value="0">私有</option>        </select>    </div></div>

选中方法:

$("#typeId").val(data.type); /**/data.type为后端返回的数据需要注意的是json属性的值要与optionvalue属性值一致,否则不能选中**

Radio:

<div class="form-group">    <label for="" class="col-sm-3 control-label">账号状态</label>    <div class="col-sm-9">        <label class="radio-inline">            <input type="radio" name="status" value="1" >            有效        </label>        <label class="radio-inline">            <input type="radio" name="status" value="0">            无效        </label>    </div></div>

选中方法:

$("input[name=status][value=" + data.status + "]").attr("checked", true);
原创粉丝点击