首页 > 代码库 > jquery 根据后台传过来的值动态设置下拉框、单选框选中

jquery 根据后台传过来的值动态设置下拉框、单选框选中

jquery  根据后台传过来的值动态设置下拉框、单选框选中

 1 $(function(){
 2     var sex=$("#sex").val();
 3     var marriageStatus=$("#marriageStatus").val();
 4     var education=$("#education").val();
 5     if(!isnull(sex)){
 6         //$("input:radio[name=‘sex‘][value="http://www.mamicode.com/+sex+"]").attr(‘checked‘,‘true‘);
 7         $("input:radio[name=‘sex‘][value="http://www.mamicode.com/+sex+"]").prop(‘checked‘,‘true‘);
 8     }
 9     if(!isnull(marriageStatus)){
10         //$("input:radio[name=‘marriageStatus‘][value="http://www.mamicode.com/+marriageStatus+"]").attr(‘checked‘,‘true‘);
11         $("input:radio[name=‘marriageStatus‘][value="http://www.mamicode.com/+marriageStatus+"]").prop(‘checked‘,‘true‘);
12     }
13     //if(!isnull(education)){
14     //    $("#education1 option[value=http://www.mamicode.com/‘"+education+"‘]").attr("selected", true);
15     //}
16     $("#education1").val(education);
17     
18 });
19 <input type="hidden" id="sex" value="http://www.mamicode.com/${serviceInfo.sex}"/>
20 <input type="radio" name="sex" value="http://www.mamicode.com/0" checked="checked"/>21 <input type="radio" name="sex" value="http://www.mamicode.com/1"/>22 <input type="hidden" id="marriageStatus" value="http://www.mamicode.com/${serviceInfo.marriageStatus}"/>
23 <input type="radio" name="marriageStatus" value="http://www.mamicode.com/0" checked="checked"/>24 <input type="radio" name="marriageStatus" value="http://www.mamicode.com/1"/>25 <input type="hidden" id="education" value="http://www.mamicode.com/${serviceInfo.education}"/>
26 <select name="education" id="education1">
27     <option value="http://www.mamicode.com/硕士">硕士</option>
28     <option value="http://www.mamicode.com/本科">本科</option>
29     <option value="http://www.mamicode.com/大专">大专</option>
30     <option value="http://www.mamicode.com/其它">其它</option>
31 </select>

 

 

jquery 根据后台传过来的值动态设置下拉框、单选框选中