今天需要生成一条option记录插入到select,采用dom的方法与先前的方法有所不同
2006-12-22 17:55
405 查看
按DOM方式
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//使用dom的方法
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$("floatingFrequencyCode").options.insertBefore(createOption(thestr, "01"),
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$("floatingFrequencyCode").options[0]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//则需要此方式来生成optino
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
function createOption(thetext, thevalue)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var theoption = document.createElement("OPTION");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
theoption.innerHTML = thetext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
theoption.value = thevalue;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return theoption;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
不按DOM方式
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
function createOption(thetext, thevalue)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var theoption = document.createElement("OPTION");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
theoption.text = thetext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
theoption.value = thevalue;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return theoption;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$("floatingFrequencyCode").options.add(createOption(thestr, "01"), 0);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//0是插入的位置,如果不写该参数,则直接追加在select尾部
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//使用dom的方法
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$("floatingFrequencyCode").options.insertBefore(createOption(thestr, "01"),
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$("floatingFrequencyCode").options[0]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//则需要此方式来生成optino
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
function createOption(thetext, thevalue)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var theoption = document.createElement("OPTION");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
theoption.innerHTML = thetext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
theoption.value = thevalue;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return theoption;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
不按DOM方式
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
function createOption(thetext, thevalue)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var theoption = document.createElement("OPTION");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
theoption.text = thetext;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
theoption.value = thevalue;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return theoption;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
$("floatingFrequencyCode").options.add(createOption(thestr, "01"), 0);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//0是插入的位置,如果不写该参数,则直接追加在select尾部
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
相关文章推荐
- html <select> <option> 实现根据选择不同的option,调用不同的方法功能
- 向数据表中插入一条记录的方法
- Vue中引入jquery方法 vue-cli webpack 引入jquery 今天费了一下午的劲,终于在vue-cli 生成的工程中引入了jquery,记录一下。(模板用的webpack)
- 用一条SQL语句实现向数据库中插入多条记录的方法
- 一条sql语句循环插入N条不同记录
- sql 中插入一条记录,然后马上取他的ID的方法
- 用一条SQL语句实现向数据库中插入多条记录的方法
- 采用DOM模型时创建一个Select节点后,要删除option项的解决方法
- 分别使用innerHTML和DOM在网页中动态生成表格的三种不同方法。
- asp如何取得新插入记录的ID(ACCESS库和MSSQL方法不同)
- 插入一条记录后,马上得到新插入记录ID值的方法
- S2SH向mysql数据库中插入记录显示问号的解决方法(采用utf-8)
- asp如何取得新插入记录的ID(ACCESS库和MSSQL方法不同) .
- 无废话Android之listview入门,自定义的数据适配器、采用layoutInflater打气筒创建一个view对象、常用数据适配器ArrayAdapter、SimpleAdapter、使用ContentProvider(内容提供者)共享数据、短信的备份、插入一条记录到系统短信应用(3)
- 如何插入一条记录获取插入后的自动增长ID列的方法.
- 向数据库中插入一条记录后如何获得自动生成的列值?
- 三种返回mysql 插入一条记录返回该记录id方法
- mysql查询最后几条、生成一条包含多条记录、插入语句、差值查询
- 插入一条记录后,马上得到新插入记录ID值的方法。good
- 写了一条Sybase SQL语句,用于生成一个表中所有数据的插入记录的生成