当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript options属性集合操作代码

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 javascript options属性集合操作代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 335 ::
收藏到网摘: n/a

javascript options属性集合操作代码,一般情况需要控制option的朋友朋友需要了解的知识。
复制代码 代码如下:

<form name="testform">
<select name="testselect">
<option value="first">first option</option>
<option value="second">second option</option>
<option value="third">third option</option>
<option>your browser can't handle this script</option>
</select>
</form>

用下面的代码可以访问到下拉框中选项:
复制代码 代码如下:

// 得到选项对象
document.forms['testform'].testselect.options[i]

如果你想删除option
复制代码 代码如下:

document.forms['testform'].testselect.options[i] = null;

把这个选项对象标志为null,这个选项就完全从列表中删除了。
注意:这个操作会影响option的数量。假设在上面的实例中,你删除了option[1] ,原来的option[2] 元素('Third option')会变成option[1] 元素(option元素按照先后顺序顶上去)。
创建一个新的option,如下:
复制代码 代码如下:

document.forms['testform'].testselect.options[i] = new Option('new text','new value');

用户在页面中看到option显示的文本和value值是这个option的VALUE 属性。
当表单提交时,VALUE 值传递到WEB服务器。
如果想要全部清空 select box 中的options, 如下:
复制代码 代码如下:

document.forms['testform'].testselect.option.length = 0;