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="+sex+"]").attr(‘checked‘,‘true‘); 7 $("input:radio[name=‘sex‘][value="+sex+"]").prop(‘checked‘,‘true‘); 8 } 9 if(!isnull(marriageStatus)){ 10 //$("input:radio[name=‘marriageStatus‘][value="+marriageStatus+"]").attr(‘checked‘,‘true‘); 11 $("input:radio[name=‘marriageStatus‘][value="+marriageStatus+"]").prop(‘checked‘,‘true‘); 12 } 13 //if(!isnull(education)){ 14 // $("#education1 option[value=‘"+education+"‘]").attr("selected", true); 15 //} 16 $("#education1").val(education); 17 18 }); 19 <input type="hidden" id="sex" value="${serviceInfo.sex}"/> 20 <input type="radio" name="sex" value="0" checked="checked"/>男 21 <input type="radio" name="sex" value="1"/>女 22 <input type="hidden" id="marriageStatus" value="${serviceInfo.marriageStatus}"/> 23 <input type="radio" name="marriageStatus" value="0" checked="checked"/>是 24 <input type="radio" name="marriageStatus" value="1"/>否 25 <input type="hidden" id="education" value="${serviceInfo.education}"/> 26 <select name="education" id="education1"> 27 <option value="硕士">硕士</option> 28 <option value="本科">本科</option> 29 <option value="大专">大专</option> 30 <option value="其它">其它</option> 31 </select>
时间: 2024-12-13 13:14:46