如何在 js文件中设置 html:select 的选项。
我在脚本中通过ajax方法得到数据,然后 select1= document.getElementById("selectName")
var option1 = document.createElement("OPTION");
select1.options.add(option1);
option1.value=list[i];
option1.innerText=list[i+1];添加select 的选项。 添加完了以后我想让它默认选择第一个。 因为不默认选择第一,它会是默认选择一个空白。
我使用过 select1.value=0; 和 select1.selectedIndex=0; 都不行 请教各位高手我该如何实现
我在脚本中通过ajax方法得到数据,然后 select1= document.getElementById("selectName")
var option1 = document.createElement("OPTION");
select1.options.add(option1);
option1.value=list[i];
option1.innerText=list[i+1];添加select 的选项。 添加完了以后我想让它默认选择第一个。 因为不默认选择第一,它会是默认选择一个空白。
我使用过 select1.value=0; 和 select1.selectedIndex=0; 都不行 请教各位高手我该如何实现
select1= document.getElementById("selectName")
var option1 = document.createElement("OPTION");
option1.value=list[i];
option1.text=list[i+1];
option1.selected=true;
select1.options.add(option1);
var arrYear = new Array(4);
for(i = 0; i< arrYear.length;i++){
arrYear[i] = date.getYear()+i;
yyyy.options.add(new Option(arrYear[i].toString(), arrYear[i].toString()));
}
这样子的话select标签就会默认选择今年作为第一个。
if (select1.options.length>0)
{
select1.options[0].selected=true;
}
http://www.cnblogs.com/guodaxia/archive/2009/05/13/1456358.html
var option1 = document.createElement("OPTION");
option1.value = list[i];
option1.innerText = list[i+1];
option1.selected = "selected";select1.options[select1.options.lengths].add(option1);
<script type="text/javascript">
<!--
var arr = ["a","b","c","d"];
window.onload = function(){
var osel = document.getElementById("osel");
for(var i = 0; i < arr.length; i++){
if(i == 1){
osel.options.add(new Option(arr[i],arr[i],false,true));
}else{
osel.options.add(new Option(arr[i],arr[i]));
}
}
}
//-->
</script>
select.options[i]=new Option(text,value);
select.options[0].selected=true;
jquery 超级select插件 v3.2.0.0版本 支持汉字、头写拼音、英文快速定位查询的超级select插件。可方向键、tab 键快速选择。 支持 ie6.0、7.0、8.0、firefox all 版本的历史版本如下:3.2.0.0版本:http://blog.csdn.net/fkedwgwy/archive/2010/06/13/5669690.aspx2.1.0.0版本:http://code.google.com/p/omcode/downloads/detail?name=selectsearchv2.1.0.rar&can=2&q=#makechanges1.0.0.0版本:http://blog.csdn.net/fkedwgwy/archive/2010/04/15/5489789.aspx