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

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 中的 javascript options属性集合操作代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 330 ::
收藏到网摘: 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;