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;
}
};
参考
2. http://blog.csdn.net/ch5256865/article/details/48265313
版权声明:原创作品,如需转载,请注明出处。否则将追究法律责任
本文转自 曦羽 51CTO博客,原文链接:http://blog.51cto.com/exist/1959678