如何在JavaScript的CascadingDropDown中获取选定的“文本"而不是“值" [英] How do I get the selected 'text' not the 'value' in a CascadingDropDown in JavaScript
问题描述
我要编写的某个应用程序有一个客户端要求,即不要将带有句点的字符串从CascadingDropDown传递回数据库,而是在屏幕上的框中显示句点.
如此简单,在我的Web服务中,我返回了一个CascadingDropDownNameValue对象,该对象的名称带有句点,而值没有.
现在,说我想从JavaScript中访问名称",即屏幕上下拉框中显示的文本,即
A certain application I am wanting to write has a client requirement to not pass strings with periods in them back to the database from a CascadingDropDown, but do show the period in the box on the screen.
So easy enough, in my web service I have it return a CascadingDropDownNameValue object with the name with periods and the values without.
Now, say I want to access the "names" i.e., the text showing in the dropdown box on screen, from JavaScript, i.e.
ddlModel.options[ddlModel.selectedIndex].text;
我知道我可以通过使用
来获取值",即下拉菜单中的文本背后"
I know I can get the "value" i.e., the text "behind" the dropdown by using
ddlModel.options[ddlModel.selectedIndex].value;
但我不想要值",我想要显示的文本".但是该行
but I don''t want the "value" I want the displayed "text." However the line
ddlModel.options[ddlModel.selectedIndex].text;
并没有像我想要的那样给我带有句号的文本.有任何提示吗?
Brian
isn''t giving me the text that has the period in it, like I want. Any hints?
Brian
推荐答案
您尝试过使用JQuery吗?
Have you tried with JQuery?
("#ddlModel:selected").text();
("#ddlModel:selected").text();
或
or
("[id
这篇关于如何在JavaScript的CascadingDropDown中获取选定的“文本"而不是“值"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!