如何通过javascript从ajax.net ComboBox获取选定的值
我需要通过 javascript 从 ajax.net 组合框获取选定的值,以便我可以进行一些客户端验证。
最好的方法是什么? 谢谢,
我已经能够通过以下方式获取值:
var combo = $get('ddlComarcas');
var comboHidden = $get('ddlComarcas_HiddenField');
var o4 = combo.getElementsByTagName('li')[comboHidden.value].childNodes[0];
alert('"' + o4.data + '"');
但我仍然需要从 o4.data 中修剪该值。任何人都可以指出如何做那个 Visual Studio 2008 jquery?
I need to get the selected value from an ajax.net combobox throught javascript so that I can do some client side validation.
What's the best way to do this?
Thanks,
I've been able to get the value with this:
var combo = $get('ddlComarcas');
var comboHidden = $get('ddlComarcas_HiddenField');
var o4 = combo.getElementsByTagName('li')[comboHidden.value].childNodes[0];
alert('"' + o4.data + '"');
But I still need to trim the value from o4.data. Anyone can point how to do that visual studio 2008 jquery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 jQuery 或仅使用 DOM:
jQuery:
DOM:
asp.net ->服务器端
JavaScript ->客户端
You can use jQuery or just use DOM:
jQuery:
DOM:
asp.net -> server side
javascript -> client side
我认为答案是客户端不存在值,因此无法检索它。有更简单的方法来获取索引(假设初始化已完成)。
据我所知,在客户端验证组合框需要对索引或文本有一定的信心,或者需要某种服务器端解决方法。
为了提供主题行的直接答案,可以使用每个组合框值在服务器端创建一个 JavaScript 数组,然后通过选定的索引引用客户端...
代码隐藏:
aspx:
I think the answer is value doesnt exist client side so it cant be retrieved. There are easier ways to get index tho (assuming whatever initialization is complete).
As far as I can tell, validating a combobox on the client requires some faith in index or text, or some kind of server side workaround.
To provide a direct answer to the subject line, a javascript array could be created server side with each combobox value and then referenced client side by selected index...
codebehind:
aspx:
这在 IE 和 Chrome 中有效(今天) - IE 唯一有用的是调试器 f12 ( - 你可以浏览监视的对象
Following
// i do it on button but you could probably do it on a combo event
Follow
this works (today) in IE and Chrome - about the only thing ie is good for is the debugger f12 (- you can browse through the watched objects
Following
// i do it on button but you could probably do it on a combo event
Follow