Home > Web Front-end > JS Tutorial > body text

javascript options属性集合操作代码_表单特效

WBOY
Release: 2016-05-16 18:38:04
Original
1170 people have browsed it
复制代码 代码如下:





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

// 得到选项对象
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;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!