_javascript tips on bug issues that still appear in the Drop-down list after suggest quick deletion

Source: Internet
Author: User

When writing suggest, sometimes we quickly delete the text of the input box, but the Suggest Drop-down list still appears because of the Ajax asynchronous request.

Although we have deleted the contents of the input box, we have even done something to stop the subsequent requests, but since Ajax is asynchronous, even if you stop the subsequent operation, the last requested data is still on the way back.

Solution to see Code:

var inp = document.getElementById (' InP '),
timer = 0;
Inp.oninput = function (e) {
var val = e.target.value;
var f = function () {
alert (val)
}
if (val = = ") {
f = function () {
Console.log (' setstate = [] '); c11/>}
}
cleartimeout (timer);
Timer = settimeout (function () {
f ();
},);
}

I paste the code here is just to solve the idea, to get the data back to the request of the subsequent related operations encapsulated into the function, when the value is empty, the function of the operation changes, will not appear suggest data box.

The above is a small set up for you to introduce the suggest quickly deleted after the drop down list of bug problems, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.