jquery 根據後臺傳過來的值動態設置下拉框、單選框選中
阿新 • • 發佈:2017-07-07
url selected ros info fun cte blog font function
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="+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>
jquery 根據後臺傳過來的值動態設置下拉框、單選框選中