js动态设置Select中Option选中 Js代码 var select = document.getElementById(selectYear); var nextYear = ‘2012’; for(var i=0; i if(select.options[i].innerHTML == nextYear){
来源: js动态设置Select中Option选中 – F7ANTY的专栏 – 博客频道 – CSDN.NET
js动态设置Select中Option选中
- 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;
- }
- }
- };
转载自http://fanshuyao.iteye.com/blog/1986616