【问题标题】:Ajax Combobox - SelectedIndex unchaged after deletingAjax Combobox - SelectedIndex 删除后取消
【发布时间】:2012-12-06 17:52:08
【问题描述】:

从 ajax 组合框中删除所有文本不会导致 selectedindex 更改。如果我选择第 0 项然后删除所有内容,或者只留下空格,它仍然说第 0 项被选中。有人知道解决方案吗?除了“下拉列表”,我越来越后悔试图用这种可怕、可怕、漂亮但可怕的控件代替它......

【问题讨论】:

  • 我还需要它来触发 .add_propertyChanged 事件或另一端的任何事件,不要挑剔
  • 如果有办法手动调用 propertyChanged 事件,我可以破解其余的

标签: combobox selectedindex


【解决方案1】:
$(".formcombobox :input[type=text]").each(function (i) {
  this.onblur = function () {
    var comboBox = $find(this.parentNode.parentNode.parentNode.parentNode.parentNode.id); // the combobox
    if (jQuery.trim(comboBox.get_textBoxControl().value) == "") { // if textbox is empty
      comboBox.set_selectedIndex(-1);                             // then set selected index to -1                       
    }
  }
});

假设组合框有 class="formcombobox",这会将 onblur 事件附加到文本框,并且 set_selectedIndex() 函数会触发更改事件,因此这将在用户离开时更正索引一个空白值并允许我处理更改

我觉得可能有更好的方法来获取父母,但无论如何。对我来说已经足够了

我想知道如果有一个合法的空白选项会不会有不同...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-14
    • 2017-08-21
    • 2015-11-01
    相关资源
    最近更新 更多