2011-08-23 27 views
1

我有以下格式字段:JQuery驗證輸入,但使用ID爲蔡作馨領域

<input type="text" name="cities[]" id="city_zip1"/> 
<input type="text" name="cities[]" id="city_zip2"/> 
<input type="text" name="cities[]" id="city_zip3"/> 

有沒有一種方法,使通過驗證插件需要第一個,但留下的名字,因爲它是什麼? 或者使這三個要求之一,但要保持原樣。

+0

究竟這是如何被驗證?這是如何提交的? – Nayish

+0

提交像任何其他形式,它有一個更多的驗證要求是:「必需:函數(元素){返回$('輸入:複選框[編號= place_of_services1]:選中')。長度> 0}」 – Milos911

+0

所以如果複選框「place_of_services1」被選中,則應填寫其中一個字段。我不在乎它是否有任何一個字段,或者只是一個字段。 – Milos911

回答

0

完成點擊舉例。可以通過提交完成。

$("#checkforvalue").click(function(e) { 
    e.preventDefault(); 
    if ($("input#place_of_services:checked").val()) { 
     var zipentered = false; 
     $("input[id^='city_zip']").each(function() { 
      if ($(this).val().length) { 
       zipentered = true; 
      } 
     }); 

     if (zipentered) { 
      alert("value in one of the fields"); 
     } else { 
      alert("no value entered"); 
     } 
    } 
}); 

js fiddle example