问题已解决,谢谢。
见文本框失去焦点事件。
[JavaScript] 纯文本查看 复制代码 //==搜索文本框变量=================
var vSouSuoInp = "",
vTypeahead,
arrResponse = [];
vTypeahead = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "null",
wildcard: '%QUERY',
rateLimitBy: 'throttle',
rateLimitWait: 2000,
transform: function (response) {
arrResponse = response;
return response;
}
}
});
//==搜索文本框变量赋值=================
$("#divMainContent").on("focus", ".typeahead", function () {
let arrDataSousuo = $(this).data("sousuo").split(",");
vSouSuoInp = arrDataSousuo[0];
vTypeahead.remote.url = arrDataSousuo[1] + '?key=%QUERY&vBiao=' + arrDataSousuo[2] + '&vZiDuan=' + arrDataSousuo[3] + '&vDISTINCT=' + arrDataSousuo[4];
if ($(this).data("inset") == "0") {
$('.typeahead').typeahead({
minLength: 2,
highlight: true
}, {
name: 'arr-Typeahead',
limit: 10,
display: 'value',
source: vTypeahead,
templates: {
notFound: '<span style="margin: 0 10px"><i class="icon-exclamation-sign"> </i>无匹配结果</span>'
}
});
$(this).data("inset", "1");
$(this)[0].focus();
};
});
//==搜索文本框失去焦点=================
$("#divMainContent").on("blur", ".typeahead", function () {
if ($(this).val() != "") {
for (i = 0; i < arrResponse.length; i++) {
if ($(this).val() == arrResponse[i]["value"]) {
return
};
};
$(this).typeahead('val', "");
}
}); |