/* Set given parameter key name as suggestions to the bind text field */
var suggestionToDisplay = [];
var suggestionFound = false;
var datas = [];
$.fn.setSuggestionField = function (option1, option2) {
var map = {
17: false,
32: false,
77: false
};
$(this).autocomplete({
minLength: 0,
source: function (request, response) {
response(suggestionToDisplay);
suggestionToDisplay = [];
},
focus: function () {
return false;
},
select: function (event, ui) {
var textValue = this.value;
/* add the selected item */
var data = ui.item.value;
/*
* Replace the hint word with selected data if
* suggestionFound is true otherwise append to hint word
*/
if (suggestionFound) {
textValue = textValue.substring(0, textValue.lastIndexOf("}") + 1);
for (i = 0; i < datas.length; i++) {
if (datas[i].key == data) textValue += "@{" + datas[i].value + "}";
}
} else {
for (i = 0; i < datas.length; i++) {
if (datas[i].key == data) textValue += "@{" + datas[i].value + "}";
}
}
this.value = textValue;
datas = [];
return false;
}
}).keydown(function (e) {
if (e.keyCode in map) {
map[e.keyCode] = true;
var inputLetters = $(this).val();
if (map[17] && map[32]) {
datas = option1;
/* Get the suggestion values for text field */
suggestionToDisplay = [];
setSuggestionOptions(inputLetters);
$(this).autocomplete('search');
} else if (map[17] && map[77]) {
datas = option2;
/* Get the suggestion values for text field */
setSuggestionOptions(inputLetters);
$(this).autocomplete('search');
}
}
}).keyup(function (e) {
if (e.keyCode in map) {
map[e.keyCode] = false;
}
});
}
当此功能绑定到ctrl +“”或ctrl + m的文本字段时,会给出建议。它在Google Chrome,Mozila上正常运行,但在Internet Explorer上ctrl + m可以正常运行,但在ctrl + space上运行不正常。空格,它会显示建议字段,并在我按下空格键后立即添加空间。因此建议字段消失了。如何解决此问题
要禁用兼容模式,请添加]>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
在您的html标头中。