select标签 selected 选中状态动态设置
方法1:
证件类型:<select id="zj"> <option value=""> 所有 </option> <option value="IDCARD" <c:if test="${requestScope.certidType=='IDCARD'}">selected="true"</c:if>> 身份证 </option> <option value="PASSPORT" <c:if test="${requestScope.certidType=='PASSPORT'}">selected="true"</c:if>> 护照 </option></select>
?方法2:
window.onload=function(){ var userType='${userType}'; if(userType == '1') { var code='${code}'; var QState='${QState}'; var selectCode=document.getElementById("code"); var selectQState=document.getElementById("QState"); if(selectCode.length>0){ for(var i=0;i<selectCode.options.length;i++){ if(selectCode.options[i].value==code){ selectCode.options[i].selected=true; break; } } } if(selectQState.length>0){ for(var i=0;i<selectQState.options.length;i++){ if(selectQState.options[i].value==QState){ selectQState.options[i].selected=true; break; } } } }}?