【问题标题】:Call a function on losing focus from typeahead (Bootstrap UI)从 typeahead 中调用失去焦点的函数(Bootstrap UI)
【发布时间】:2015-01-17 10:44:36
【问题描述】:

我正在使用 Bootstrap UI 的 typeahead。每当从下拉列表中选择新选项或用户输入了一些值时,我都需要调用不同的函数。所以,为此我尝试使用ng-blur。如果我们输入 2 或 3 个字符并准备从下拉列表中进行选择,ng-blur 将被这 2 或 3 个字符触发,并且在进行选择之后也是如此。我只想在 typeahead 输入框失去焦点后触发该功能。

<input type="text" ng-model="$parent.selected" placeholder="Select a value..." typeahead="text for text in getOptions($viewValue)" required ng-blur="getDifferentFunction($parent.selected)" typeahead-editable="true" />

有什么帮助或建议吗?

【问题讨论】:

    标签: angularjs angular-ui-bootstrap typeahead.js bootstrap-typeahead angular-ui-typeahead


    【解决方案1】:

    为 on-blur 函数添加超时,这样您就可以在 500 毫秒内获得所选的更改更新。由于 javascript 并行运行,它应该做得很好。

    function onBlurAction(){
      setTimeout(function(){ 
        //your code here
      }, 500);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-06
      • 1970-01-01
      相关资源
      最近更新 更多