2017-09-19 74 views
1

我有一个类型提前为我输入如下,如何限制提前输入选项从键盘中选择?

<input 
    typeahead-template-url="app/templates/type-a-head-item.html" 
    type="text" 
    ng-model="selectedDisease" 
    search-head="powerSearch" 
    typeahead-loading="loadingLocations" 
    typeahead-wait-ms="200" 
    typeahead-min-length="0" 
    placeholder="Disease, Procedure or Medicine" 
    typeahead="match as match._source.name for match in getDiseases($viewValue)" 
    typeahead-focus-first="false" 
    typeahead-editable="false" 
    typeahead-loading="loadingDiseases" 
    class="form-control input-lg ng-pristine ng-untouched ng-invalid ng-invalid-required magnifyInput Bcolor" 
    typeahead-on-select="searchDoctors()" 
    aria-autocomplete="list" 
    aria-expanded="false" 
    aria-owns="typeahead-12-6891"> 

我要选择的选项只从下拉而不是通过选择与键盘enter.I试过很多方法使用jQuery,但没有工作。任何人都可以请建议我help.Thanks。

$(document).keypress(function(e) { 
    if(e.which == 13) { 
     alert('You pressed enter!'); 
    } 
}); 
+1

'我试过很多方法'=>试着分享。 –

+0

@ mt1:您的问题已解决...?如果你找到了解决方案,那么你可以与我们分享... :) –

回答

0

添加此属性应该达到你想要的行为:

typeahead-should-select="false" 

docs

预输入,应该选择($事件)(默认:空)

当可能触发sel的关键事件时执行的回调发生。 只有当此函数返回true时才会进行选择。

+0

嗨marsze,我只是把typeahead-should-select =“false”但不工作 – mt1

+0

@ mt1我自己试了一下,它的工作方式和预期的一样。定义“不工作”或澄清你想要的行为。 – marsze

+0

其实我只是在我的输入中粘贴了'typeahead-should-select =“false”'这一行,而且ddid没有做任何改变,但typeahead的行为没有改变。我是否需要改变其他任何东西。 – mt1