JS给select设置默认选中的值,添加selected属性
html:
<select name="setvalue" id="setvalue" data-id="3"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select>
<input type="hidden" value="3" id="selectval">
JS:
var selectval= document.getElementById("selectval").value; var selectid = document.getElementById("setvalue"); for(i=0;i<selectid.length;i++){ if(selectid[i].value==selectval) selectid[i].selected = true; }