【发布时间】:2019-03-25 19:38:55
【问题描述】:
在发布这个问题之前,我尝试了 StackOverflow,但没有找到答案。
所以,问题是,我有一个包含一些值的数组(假设为 4、6、7、8、10 等)。我使用jquery的.each函数来提示alert信息。但是我的代码给了我一条警告消息,将焦点放在所需的输入框上并提交表单并且不会“返回 false”。 我希望它在聚焦后返回 false。
$(document).on('keypress','#create_invoice',function(){
$.each(newArr, function( i, l ){
//alert( "Index #" + i + ": " + l );
if($.trim($('#item_name'+l).val()).length == 0)
{
alert("Please Enter Item Name");
$('#item_name'+l).focus();
// return false; //if use this not work and submit form
}
//return false; //if use this not work and submit form
});
//return false; if i use this then submit() not work
$('#invoice_form').submit();
});
【问题讨论】:
标签: javascript jquery