如何在SELECT元素中找到特定选项 [英] How to find that a particular option is there in a SELECT element

查看:95
本文介绍了如何在SELECT元素中找到特定选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的页面有一个SELECT(下拉列表)元素,我必须动态添加选项。在添加之前我必须知道该选项是否已存在于下拉列表。


i尝试了这个....

if(myDropDown.options [2] .text ==" NewYork"){

............

这会检查下拉列表的第3个选项,但我想检查所有选项。

i可以使用像这样的for循环来执行每个选项....

for(i = 0; i< options.length; i ++)

{

if(myDropDown.options [2] .text ==" NewYork"){

.......... 。

}


这是检查选项是否已经存在的唯一方法吗?

有什么我的吗?可以尝试这样....

myDropDown.options.text ==" NewYork"


对不起详细说明....感谢您的回复


-Satya

Hi all,
My page has a SELECT(drop-down list) element and i have to add options dynamically to it.Before adding i have to know whether that option is already there in the drop-down list.

i tried this....
if(myDropDown.options[2].text == "NewYork") {
............
this checks the 3rd option of the drop-down list, but i want to check all the option items.
i can go thru'' every option using a for loop like this....
for(i=0;i<options.length;i++)
{
if(myDropDown.options[2].text == "NewYork") {
...........
}

Is this the only way to check whether the option is already there or not?
Is there anything i can try like this....
myDropDown.options.text == "NewYork"

Sorry for elaboration....Thanks for any replies

-Satya

推荐答案

您的选择的详细信息是否在数据库中?

if是的尝试可以做while语句并用if语句嵌套。


如果没有尝试通过使用javascript代码手动完成它


if(document.formname.selectname.options [index] .value =="所需的值)

{

}


类似的东西...


抱歉,不能帮助那么多!

上帝保佑你!
are the details of your select is in database?
if yes try to may do while statements and nest it with if statement.

if not try doing it manually by having a javascript code like

if (document.formname.selectname.options[index].value=="the value needed")
{
}

something like that...

Sorry can''t help that much!
God Bless You!


谢谢你的回复,

但我的人口不是来自数据库,我的要求是检查浏览器端本身是否存在该特定选项。
Thanks for ur reply,
but my population is not from the database and my requirement is to check whether that particular option is there on the browser side itself.



大家好,

我的页面有一个SELECT(下拉列表)元素,我必须动态地向它添加选项。在添加之前我必须知道该选项是否已经存在于下拉列表中。 />

i尝试了这个....

if(myDropDown.options [2] .text ==" NewYork"){

............

这会检查下拉列表的第3个选项,但我想检查所有选项。

i可以使用像这样的for循环来执行每个选项....

for(i = 0; i< options.length; i ++)

{

if(myDropDown.options [2] .text ==" NewYork"){

.......... 。

}


这是检查选项是否已经存在的唯一方法吗?

有什么我的吗?可以尝试这样....

myDropDown.options.text ==" NewYork"


对不起详细说明....感谢您的回复


-Satya
Hi all,
My page has a SELECT(drop-down list) element and i have to add options dynamically to it.Before adding i have to know whether that option is already there in the drop-down list.

i tried this....
if(myDropDown.options[2].text == "NewYork") {
............
this checks the 3rd option of the drop-down list, but i want to check all the option items.
i can go thru'' every option using a for loop like this....
for(i=0;i<options.length;i++)
{
if(myDropDown.options[2].text == "NewYork") {
...........
}

Is this the only way to check whether the option is already there or not?
Is there anything i can try like this....
myDropDown.options.text == "NewYork"

Sorry for elaboration....Thanks for any replies

-Satya



是的,你必须循环,但你可以突破循环你找到一个匹配。

Yes, you''ll have to loop through, but you can break out of the loop once you find a match.


这篇关于如何在SELECT元素中找到特定选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆