gpt4 book ai didi

javascript - 如何在文本框中传递一个额外的隐藏按键?

转载 作者:行者123 更新时间:2023-12-03 08:33:26 24 4
gpt4 key购买 nike

如何将一个额外的隐藏按键传递到文本框?因为此代码需要按一次额外的按键来加载自动完成下拉列表中的列表。

$( document ).ready(function() {

$("#zipcode").on("keyup", function(event) {
if(this.value.length == 5){
var zicpcode= $("#zipcode").val();
$.ajax({
url: "http://pages.em.essilorusa.com/page.aspx?QS=773ed3059447707d2a7242227e94bba8efcc7ce6da09facd&zip="+zicpcode,
type: "get", //send it through get method
success: function(results) {
var res=results.substring((results.indexOf("<rs1>")+5),results.indexOf("</rs1>"));
var splitted = res.split("|");
var distinct = [];

$.each(splitted , function(i, el){
if($.inArray(el, distinct ) === -1)
distinct.push(el);
});
$("#zipcode").autocomplete({ source: distinct });
},
});
}
});
});

最佳答案

似乎在 input type="text".autocomplete 中已有五个字符后加载 .autocomplete() source () 未初始化,下拉菜单直到输入第六个字符才出现?

尝试

$("#zipcode").autocomplete({
minLength:5,
source:function(request, response) {
var term = request.term;
if ( term in cache ) {
response( cache[ term ] );
return;
}

$.getJSON( "http://pages.em.essilorusa.com/page.aspx?QS=773ed3059447707d2a7242227e94bba8efcc7ce6da09facd&zip=" + term, function( results, status, xhr ) {

var res = results.substring((results.indexOf("<rs1>")+5),results.indexOf("</rs1>"));
var splitted = res.split("|");
var distinct = [];

$.each(splitted , function(i, el){
if($.inArray(el, distinct ) === -1)
distinct.push(el);
});
cache[ term ] = distinct;
response( distinct );
});
}
})

jsfiddle https://jsfiddle.net/g5zn9fs9/

参见Autocomplete - Remote with caching

关于javascript - 如何在文本框中传递一个额外的隐藏按键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33270195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com