当 jQuery 自动完成没有找到结果时,我想禁用我的提交。我现在工作一半,我计算我的结果很好。
唯一的问题是当我有结果并且我提交时,结果会弹回 0,所以我无法提交。我想在提交时记住自动完成计数值。
我计算我的结果:
$('#stock_input').autocomplete({
source:'autocomplete.php',
autoFocus: true,
minLength:1,
open: function(event,ui){
count = $(this).autocomplete("widget").find( "li" ).length;
$('#count').text(count);
},
close: function(event,ui){
count = 0;
$('#count').text(count);
}
});
允许提交设置:
var allowSubmit = true;
$("#updatestock_form").submit(function(e){
if(count === 0){ allowSubmit = false; alert(count); }
else { allowSubmit = true; alert(count); }
if (!allowSubmit) return false;
//rest of submit code
});