使用javascript更改dropdownlist选择的索引 [英] change dropdownlist selected index with javascript

查看:81
本文介绍了使用javascript更改dropdownlist选择的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





请在下面的任何一个帮助要求。这对我来说非常有用。提前谢谢



使用javascript更改下拉列表选择的索引



例如我有两个下拉列表表单,如果我单击第一个下拉列表中的值。自动分别显示下拉列表中的scecond值。



A-下拉列表B-下拉列表



1 4

2 5

3 6





例如如果我在第一个下拉列表中点击值3 。自动分别显示6下拉列表中的秒数



这个供您参考



A-drop downlist B-drop downlist

3 6

Hi,

Please any one help below requirements. It would be very useful for me . Advance Thanks

"change dropdownlist selected index with javascript"

for example I have two dropdown list in form , If I click values in first dropdown list. automaticaly respective values to show the scecond in drop down list .

A- dropdown list B- drop down list

1 4
2 5
3 6


for example If I click values "3" in first dropdown list. automaticaly respective values to show "6" the scecond in drop down list

This For your Reference

A-drop downlist B-drop downlist
3 6

推荐答案

将文本值与给定的值匹配。如果它与选项的文本匹配,您可以将selectedIndex设置为。



Match the text value with the value you are given. If it is matched with the text of the option you can set the selectedIndex to that.

var dropdownlistbox = document.getElementById("DropdownID")

for(var x=0;x < dropdownlistbox.length -1 ; x++)
{
   if(givenValue == dropdownlistbox.options[x].text)

      dropdownlistbox.selectedIndex = x;
}





如果您知道索引然后直接就可以这样给出



if you know the index then directly you can give like this

document.getElementById("DropDownID").selectedIndex = x;


这篇关于使用javascript更改dropdownlist选择的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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