2010-05-18 19 views
0

我有一個用戶控制如何使用戶CONTROLER複選框的選擇條件

<input id="check" type="checkbox" /> 
<label>&nbsp;</label> 
<fieldset class="clearfix" id="fieldset-exception"> 
    <legend>Student Information</legend> 
    <div class="fiveper"> 
     <label for="StudentID"> 
      Exception ID: 
      <span><%=Html.EditorFor(x => x.studentid)%></span> 
     </label> 
     <label for="Classroom"> 
      Origination: 
      <span><%=Html.EditorFor(model => model.Classroom)%></span> 
     </label> 
     <label for="Subject"> 
      Age: 
      <span><%=Html.EditorFor(model => model.subject)%></span> 
     </label> 
</div> 
$('#btnAll').click(function() { 
      $('#Details input[type=checkbox]').attr('checked', 'checked'); 
     }); 

我使用上面的代碼 檢查所有的複選框,但我需要的條件在這裏,用戶需要至少選擇一個複選框做某事? 我有其他的按鈕去基於這個複選框檢查其他頁面? 有人可以告訴我如何檢查,以及如何使這種情況? 感謝 感謝

回答

1

嘗試以下操作:

if ($("#Details input[@type=checkbox][@checked]").length < 1){ 
    return false; 
} 

有你的按鈕的onclick調用此方法,並且僅當它不返回false提交。

+0

這不是work.its什麼都不做/ – kumar 2010-05-18 15:50:12

+0

看到編輯答案 – derek 2010-05-18 17:52:07

1

嘗試這樣的事情

if ($('#Details input[@type=checkbox][@checked]').length < 1) { 
    //error 
} 

你會也想實現這種服務器端也是如此。