我有一个使用bootstrap typeahead plugin的简单ASP.NET MVC应用程序。
我有一个类型如下的预先输入:
此处直到我点击才会选中项目。但是,假设我没有点击就将鼠标悬停在列表中:
但是当我将鼠标移到窗体外时,悬停的项目现在变为选中状态:
这意味着如果我点击网站上的任何地方,那么预先输入的val()
就会成为之前悬停的项目。
如果单击类型清单中的项目,如何确保仅设置val()
?
我已经设置了autoSelect: false
设置,如果我还没有徘徊(默认选择第一项),这就解决了问题。
答案 0 :(得分:2)
我的解决方案是编辑插件。一点都不难
blur: function (e) { if (!this.mousedover && !this.mouseddown && this.shown) { //this.select(); this.hide(); this.focused = false; this.keyPressed = false; } else if (this.mouseddown) { // This is for IE that blurs the input when user clicks on scroll. // We set the focus back on the input and prevent the lookup to occur again this.skipShowHintOnFocus = true; this.$element.focus(); this.mouseddown = false; } },
这应该有效!适合我;)