需要 javascript 将 RADcombobox 的选定索引设置为 0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3550256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 01:29:27  来源:igfitidea点击:

need javascript to set an selected index for RADcombobox to 0

javascriptasp.net

提问by Nathan

need javascript to set an selected index for RAD combobox to 0

需要 javascript 将 RAD 组合框的选定索引设置为 0

回答by Michael La Voie

Have you tried "ClearSelections"?

你试过“ClearSelections”吗?

var combo = $find("<%= RadComboBox1.ClientID %>");
combo.clearSelection();

EDIT

编辑

Give this a shot:

试一试:

var combo = $find("<%= RadComboBox1.ClientID %>");
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
combo.trackChanges();
combo.get_items().getItem(0).select();
combo.commitChanges();

回答by Brian Mains

You should be able to do:

你应该能够做到:

var combo = $find("<%= RadComboBox1.ClientID %>");
combo.get_items().get_item(0).select();

I believe you use get_item() to get the specific item. There is a selected index, but I've seen the preference being to use the select method instead on telerik forums.

我相信您使用 get_item() 来获取特定项目。有一个选定的索引,但我在 Telerik 论坛上看到了使用 select 方法的偏好。

EDIT:The RadComboBox uses the text property to reference the text in the combo, since the text isn't required to be an item in the list. You should test, because it's probably a selected index of -1. So, you can check and see if the selected index is a -1 or other value (not 100% sure if it's -1 or null on the client-side) and then programmably perform the selection. So is that the right response though, because I think the control then may wipe out your text...

编辑:RadComboBox 使用 text 属性来引用组合中的文本,因为文本不需要是列表中的一个项目。您应该测试,因为它可能是-1 的选定索引。因此,您可以检查所选索引是否为 -1 或其他值(不能 100% 确定它在客户端是 -1 还是 null),然后以可编程方式执行选择。不过,这是正确的回应,因为我认为该控件可能会清除您的文本......