How to clear autocomplete selected values?

筅森魡賤 提交于 2019-12-21 19:42:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!