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