加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何清除从AngularUI typeahead输入的文本

发布时间:2020-12-17 08:35:13 所属栏目:安全 来源:网络整理
导读:我有一个预先输入。输入文本设置为在字母开头选择的选项。但是,我想清除这个文本,并在我从typeahead中选择一个选项后再次在文本框中显示“占位符”值(因为我在selectMatch()方法中将选定的值添加到另一个div。 input id="searchTextBoxId" type="text" ng-
我有一个预先输入。输入文本设置为在字母开头选择的选项。但是,我想清除这个文本,并在我从typeahead中选择一个选项后再次在文本框中显示“占位符”值(因为我在selectMatch()方法中将选定的值添加到另一个div。
<input id="searchTextBoxId" type="text" 
    ng-model="asyncSelected" placeholder="Search  addresses..."
    typeahead="address for address in getLocation($viewValue) | filter:$viewValue"
    typeahead-loading="loadingLocations" class="form-control"
    typeahead-on-select="selectMatch(asyncSelected)" typeahead-min-length="3"
    typeahead-wait-ms="500">

我试图使用它的Id设置Input元素的文本值和占位符值,但是没有工作,例如这些:

// the input text was still the 
$('#searchTextBoxId').attr('placeholder','HELLO');

选择结果

// the input text was still the selected result
$('#searchTextBoxId').val('');

如何设置或重置文本值?

我正在寻找一个答案,以及,最长的时间。我终于找到了一个对我有用的决议。

我最终设置NgModel为typeahead-on-select属性中的一个空字符串:

在您的typeahead-on-select属性中,添加asyncSelected =”;在你的select函数后面,像这样:

<input ...
    typeahead-on-select="selectMatch(asyncSelected); asyncSelected = '';" />

让你的最后一个字母看起来像:

<input id="searchTextBoxId" type="text" 
    ng-model="asyncSelected" placeholder="Search  addresses..."
    typeahead="address for address in getLocation($viewValue) | filter:$viewValue"
    typeahead-loading="loadingLocations" class="form-control"
    typeahead-on-select="selectMatch(asyncSelected); asyncSelected = '';" 
    typeahead-min-length="3"
    typeahead-wait-ms="500">

Fiddle assigning the value to a variable

Fiddle adding each selection to an array

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读