關於怎么將后台的數據放在select-option的默認選擇


select默認選擇你要的值都是怎么將你要的值放上selected

1.jsp中可以用EL表達式。

<select  id="sex" style="height: 22px;margin-right: 20px;border: 1px solid #BABABA;color:#BABABA;border-radius: 4px;line-height: 18px;">
<option value="" style="font-size: 14px;">請選擇</option>
<option ${sex eq '1'?'selected':''} value="1">男</option>
<option ${sex eq '2'?'selected':''} value="2">女</option>
</select>
2.ajax返回值或者頁面之間傳值(1.將值取到、2.判斷)
if (unitPropertiess == 1) {
$("#unitProperties").find("option[value='1']").attr("selected", true);
} else if (unitPropertiess == 2) {
$("#unitProperties").find("option[value='2']").attr("selected", true);
} else if (unitPropertiess == 3) {
$("#unitProperties").find("option[value='3']").attr("selected", true);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM