简体   繁体   English

如何在javascript中获取asp.net下拉列表项

[英]how to get the asp.net drop down list items in javascript

I have one dropdownlist in my c# code behind page like `DropDownList dl = new DropDownList(); 我在C#代码的页面后面有一个dropdownlist,例如`DropDownList dl = new DropDownList();。 dl.Items.Add("Item 2"); dl.Items.Add(“ Item 2”);

        dl.Items.FindByText("Item 2").Value="2";
        dl.Items.Add("Item 3");

        dl.Items.FindByText("Item 3").Value="3";`   

I like to get that drop down list items in client side java script. 我喜欢在客户端Java脚本中获得该下拉列表项。 one important think note that I like to get values of dropdownlist in the c# code behind page and not the asp.net page. 一个重要的思想注意事项,我喜欢在页面而不是asp.net页面的c#代码中获取dropdownlist的值。 Can anyone know the solution for that problem? 谁能知道该问题的解决方案?

Thank you... 谢谢...

在浏览器中“查看源代码”,找到下拉列表,然后相应地编写Javascript。

var ddl= document.getElementById("<%=ddl.ClientID%>");
var Text = ddl.options[ddl.selectedIndex].text; 
var Value = ddl.options[ddl.selectedIndex].value; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM