2011-05-06 73 views

回答

3

綁定到這樣的形式提交事件的函數:

// assuming #foo is the form and each grouped element has classname bar 
// also, this assumes that your form is not loaded by AJAX, but only the elements 
// contained in it 
$('#foo').submit(function() { 
    var elements = $("input[name='clients[]']"); 
    var validated = false; 
    elements.each(function() { 
     if ($(this).val() != '') { 
      validated = true; 
      return false; // will break the each 
     } else { 
      validated = false; 
     } 
    }); 
    return validated; 
}); 

​​

+0

由於ajax返回的字符串,你是不是忘了'.live'函數? – 2011-05-06 07:50:34

+0

在提交表單後,元素被綁定*,因此在這種情況下不需要使用「live()」。 – 2011-05-06 07:52:02

+0

謝謝!現在我明白了。 BTW很棒! +1 – 2011-05-06 07:52:44

0

像這樣:

var $filledTextboxes = $(":text[name='clients[]']").filter(function(){ 
    return $.trim($(this).val()) != ""; 
}); 
if($filledTextboxes.size() == 0) 
    alert("All are empty"); 
else 
    alert("Not all are empty"); 

希望這有助於。乾杯

+0

謝謝埃德加。這將通過ajax輸入加載嗎?謝謝! – udexter 2011-05-06 07:46:45

相關問題