function checkInput() { var $tr = $("#tb_confirmed .scrollContent").find("tr"); var flag = 0; var antiqueTypes = []; $tr.each( function( index, item ){ var type = $(item).find("input[type='text']").val(); antiqueTypes.push(type); }); $.each(antiqueTypes, function(index, item){ if( item.length == 0 ){ flag += 1; $("order-tips").find("span").text("請輸入商品物流單號"); } }); return flag; } // 調用此方法, 可以在別的方法中調用它 if( checkInput > 0 ){ $("order-tips").find("span").text("請輸入商品物流單號"); return false; } else { ajax() // 請求 }