第一种用each遍历
$("input[name='productNames']").each(function(){
if( $(this).val().trim() == '') { layer.tips('请填写产品名称!', this,{ time: 3000, tips: 2, tipsMore: true
});
scrollOffset($("#productNames").offset(),300);
flag=false; return; }
});
第二种用for循环
var pname =$("input[name='productNames']"); for ( var i = 0; i < pname.length; i++) { if(pname[i].value==""){ layer.tips('请填写产品名称!', pname[i],{ time: 3000, tips: 2, tipsMore: true }); scrollOffset($("#productNames").offset(),300); flag=false; return; } }