2016-07-12 80 views
0

我想編碼按鈕無線電驗證。 (是或否)。謝謝。 我的代碼:jquery驗證條件值

conditions : { 
    required : { 
     depends: function(element) { 
      if ($('#conditions')val('Yes').is(':checked')){ 
       return true; 
      }else{ 
       return false; 
      } 
     } 
    } 
}, 
+0

是的,我想品嚐如果是或否。如果沒有錯誤消息它是通過。謝謝。 – Evane

回答

0

你可能想返回羯羊或沒有無線電與價值"Yes"檢查或沒有,因爲ID是唯一的,我們會假設單選按鈕的ID爲#conditions

conditions : { 
    required : { 
     depends: function(element) { 
      return $('#conditions').is(':checked'); 
     } 
    } 
}, 
+0

謝謝@adeneo。你的解決方案幫助我。 – Evane

0

給唯一ID到YES單選按鈕,並使用下面的代碼:

if ($('#uniqueid').prop("checked")) { 
    return true; 
} else { 
    return false; 
} 

在短:

return $('#uniqueid').prop("checked") 

希望這會有所幫助。

+0

這是工作,但我得到錯誤信息返回true和false。 – Evane

+0

你得到的錯誤信息是什麼? – ajaysinghdav10d