gpt4 book ai didi

javascript - 仅在输入两个或更多字符时触发 AJAX

转载 作者:行者123 更新时间:2023-11-30 13:48:26 24 4
gpt4 key购买 nike

我有以下代码:

<script>
function pesquisa_cid_01() {
var oHTTPRequest = createXMLHTTP();
oHTTPRequest.open("post", "bd_ajax_ciat_cid.asp", true);
oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oHTTPRequest.onreadystatechange=function() {
if (oHTTPRequest.readyState == 4) {
document.all.div_pesquisa_cid_01.innerHTML = oHTTPRequest.responseText;
}
}
oHTTPRequest.send("busca_cid_01=" + encodeURIComponent(form_ciat_new.pesquisa_cid_01_form.value));
}
</script>

如何强制代码仅在表单输入中输入 2 个以上字符时才开始工作?

表单代码为:

<input type="text" name="pesquisa_cid_01_form" id="pesquisa_cid_01_form" class="form-control" onkeyup="pesquisa_cid_01();">

最佳答案

只检查值的长度,如果不正确则退出。

function pesquisa_cid_01(e) {
if (e.currentTarget.value.length < 2) {
return;
}

...
}

关于javascript - 仅在输入两个或更多字符时触发 AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58807989/

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