jsp代碼html
<select id="typeId" class="form-control"> <option value="1">手機</option> <option value="2">話費</option> </select>
jquery代碼jquery
$("#typeId option").each(function(){ if($(this).val()=='${template.typeId}'){ $(this).attr('selected',true); } });
jquery中的${template.typeId}是頁面加載時傳過來的數據ajax
${template.typeId}在不一樣的條件下能夠有不一樣的傳入方式,jsp
好比html+jquerythis
其餘代碼都同樣,你只須要ajax取得要用的值便可spa
好比jsp(freemarker)+jquerycode
和原文實例同樣orm