1. 程式人生 > >從頁面獲取多個相同name的input文字框的值的方法

從頁面獲取多個相同name的input文字框的值的方法

第一種用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; 
}
}