问题
I have a page with several JQuery autocompletes. I have implemented a button to clear all selected values, but it does not work... I have tried to set $(...).text("");
but it does not work. Firebugs fails on the line and does not throw any error message. It quits the function.
What is the right way to clear the selected value of JQuery autocompletes, from code?
回答1:
Try using $(...).attr("value","");
Hope it works!! Sorry if i have misunderstood the question.
回答2:
You should use:
$('selector').autocomplete('close').val('');
This will also reset the current search of the autocomplete (in addition to clearing the input).
回答3:
You should use this one, it'll work
$("selector").autocomplete({
source: ,
delay: 200,
minLength: 3,
select: function (event, ui) {
ui.item.value = ""; // it will clear field
return false;
}
});
回答4:
Try this,
$("selector").autocomplete({
source: ,
delay: 200,
minLength: 3,
select: function (event, ui) {
$(this).val() = "";
return false;
}
});
来源:https://stackoverflow.com/questions/8867604/how-to-clear-autocomplete-selected-values