如何在 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; 都不行 请教各位高手我该如何实现
解决方案 »
- 求一个兼容谷歌浏览器的加入收藏js
- 关于复选框的全选全否
- js控制表格显示问题
- 关于编辑器提交html标签空格和换行的问题(小马哥)
- js 自动刷新jsp页面
- 怎样获得页面元素大小?
- ext探讨:可编辑grid里能根据数据类型的不同自动变换用下拉列表、日期选择、单选、多选和文本输入等的编辑方式吗?
- 我建立了一个群,主要用于探讨HTML,DHTML,CSS,JAVASCRIPT,FLASH,DREAMWEAVER,PHOTOSHOP技术,希望从事这方面工作的同志加入
- 请教高手,化境上传的文件大小限定问题?
- 网页A重定向到网页B,如何在网页B中知道网页A的地址?
- jquery 超级select插件 v3.2.0.0版本 支持汉字、头写拼音、英文快速定位查询的超级select插件。可方向键、tab 键快速选择.
- 关于jquery插件
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