时间:2021-07-01 10:21:17 帮助过:10人阅读
var select = document.getElementById("selectYear");
var nextYear = '2012';
for(var i=0; i<select.options.length; i++){
if(select.options[i].innerHTML == nextYear){
select.options[i].selected = true;
break;
}
}/**
* 设置select选中
* @param selectId select的id值
* @param checkValue 选中option的值
* @author lqy
* @since 2015-08-21
*/
function setSelectChecked(selectId, checkValue){
var select = document.getElementById(selectId);
for(var i=0; i<select.options.length; i++){
if(select.options[i].innerHTML == checkValue){
select.options[i].selected = true;
break;
}
}
};以上就是JavaScript如何动态设置Select中Option的选中实例分析的详细内容,更多请关注Gxl网其它相关文章!