Js代码 (测试有效)
// select.options[i].innerHTML //取显示文本
// select.options[i].value //取value值
-
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;
-
}
-
}
Js代码
-
/**
-
* 设置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;
-
}
-
}
-
};
参考
1. http://pjzz6666.iteye.com/blog/1735317
2. http://blog.csdn.net/ch5256865/article/details/48265313