当前位置: 首页 > 图文教程 > 网络编程 > Javascript > [IE&FireFox兼容]JS对select操作

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 [IE&FireFox兼容]JS对select操作


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 147 ::
收藏到网摘: n/a

今天在Ajax中使用两个下拉框动态添加select中的options,当我在IE测试下正常使用却在FireFox中不能正常使用,我对脚本也不是很熟悉,所以上网查了一下发现他们在动态添加option时有点不同。
下面把他记下来,说不定以后还可以用用:
动态删除select中的所有options:
function deleteAllOptions(sel){
sel.options.length=0;
}
动态删除select中的某一项option:
function deleteOption(sel,indx){
sel.options.remove(indx);
}
动态添加select中的项option:
function addOption(sel,text,value){
sel.options.add(new Option(text,value));
}
上面在IE和FireFox都能测试成功,希望以后你可以用上。
其实用标准的DOM操作也可以,就是document.createElement,appendChild,removeChild之类的。:)