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!