javascript中options集合怎么用

发布时间:2022-05-11 10:34:26 作者:iii
来源:亿速云 阅读:127

这篇文章主要讲解了“javascript中options集合怎么用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“javascript中options集合怎么用”吧!

object.options.add(new Option(label,value))方法向集合里添加一项option对象;
object.options.remove(index)方法移除options集合中的指定项;
object.options(index)或options.item(index)可以通过索引获取options集合的指定项;

select标记还有一个属性为selectedIndex,通过它可能获取当前选择的option索引:object.selectedIndex

1.清空options集合


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gtfunction   optionsClear(object)  
{  
var length = object.options.length;
for(var i=length-1;i>=0;i--){
e.options.remove(i);
}
}

2.添加一项新option


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gtfunction addOption(object)
{
object.add(new Option(label,value));
//使用options集合中最后一项获取焦点
   object.selectedIndex = object.lentht-1;
}

3.删除options集合中指定的一项option


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gtfunction removeOption(index)
{
if(index >=0)
{
object.remove(index);
//使用options集合中最后一项获取焦点
       object.selectedIndex = object.lentht-1;
}
}

4.获取当前选定的option的真实值value


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gtfunction getCurrentOptionValue(index)
{
if(index >=0)
return object(index).value;
}

5.获取当前选定的option的显示值label


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gtfunction getCurrentOptionLabel(index)
{
if(index >=0)
return object(index).text;
}

感谢各位的阅读,以上就是“javascript中options集合怎么用”的内容了,经过本文的学习后,相信大家对javascript中options集合怎么用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. C++中set集合怎么用
  2. javascript中options集合的用法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

javascript options

上一篇:Javascript内置变量top和parent有什么不同

下一篇:Java基础中List常用方法是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》