我是jquery的新手,我正在构建一个MVC 4网站,这是预期的,但是我希望处理这样的事件:用户清除搜索条件,然后我将我的表更新到其原始状态。
var submitAutoCompleteForm = function (event, ui) {
var $input = $(this);
$input.val(ui.item.label);
var $form = $input.parents("form:first");
$form.submit();
};
var createAutoComplete = function () {
var $input = $(this);
var options = {
source: $input.attr("data-otf-autocomplete"),
select: submitAutoCompleteForm
};
$input.autocomplete(options);
};
$("input[data-otf-autocomplete]").each(createAutoComplete);发布于 2013-07-19 22:40:56
您需要添加此选项以要求0个字符才能激活搜索:
minLength: 0启用此功能后,只需点击向下箭头,列表就会显示出来
编辑:
现在我更好地理解了这个问题,您可能需要添加" search“选项,在从源代码请求任何内容之前触发search选项,因此这是查看字段是否为空的最佳位置。
,search: function(event, ui){
if($(this).val() == ''){
//code to show table
}
},change: function(event, ui){
if($(this).val() == ''){
//code to show table
}
}发布于 2013-07-23 03:43:33
我最终使用了一种不同的方法,本质上与@MonkeyZeus建议相同
$("input[type='search']").keyup("search", function () {
if (!this.value) {
//code to update the table} });
https://stackoverflow.com/questions/17748839
复制相似问题