0
我想禁用驗證一些文本框,當某些按鈕被點擊時,例如,如果我有4個文本框,當我點擊按鈕1只有前2個文本框應該驗證,當我點擊按鈕2只有最後2文本框應該驗證,目前所有的框都驗證,我如何啓用/禁用文本框驗證使用jquery,驗證只激活在UI中可見的文本框,而不是隱藏的一個我GOOGLE了它,發現這樣的一些事情:Jquery禁用驗證問題
<script type="text/javascript">
document.getElementById("YourbuttonID").disableValidation = true;
</script>
下面是我使用的代碼:
<script type="text/javascript">
$(document).ready(function() {
var $startdates = $('#startDates');
var $endDates = $('#endDates');
var $showEvents = $('#showEvents');
$startdates.hide();
$endDates.hide();
$showEvents.hide();
$('#hide').click(function() {
$startdates.show();
$endDates.show();
$('#showEvents').show();
$('#eventdids').hide();
$(this).hide();
return false;
});
$("#hide").validate({
ignore: "#hide"
})
$('#showEvents').click(function() {
$startdates.hide();
$endDates.hide();
$('#eventdids').show();
$('#hide').show();
$(this).hide();
return false;
});
});
</script>
<tr id="startDates">
<td>
<div class="editor-label">
<%: Html.LabelFor(model => model.StartDate) %>
</div>
</td>
<td>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.StartDate) %>
<%: Html.ValidationMessageFor(model => model.StartDate) %>
</div>
</td>
</tr>
<tr id="endDates">
<td>
<div class="editor-label">
<%: Html.LabelFor(model => model.EndDate) %>
</div>
</td>
<td>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.EndDate) %>
<%: Html.ValidationMessageFor(model => model.EndDate) %>
</div>
</td>
</tr>
<tr id="eventdids">
<td>
<label>Events</label>
</td>
<td>
<% foreach (var item in (SelectList)ViewData["events"]) { %>
<input type="checkbox" name="Name" value="<%=item.Value %>" />
<label for="<%=item.Value%>"><%=item.Text%></label>
<br />
<% } %>
</td>
<td><input type="button" name="Select" id="hide" style="width:auto" value="Select All Events" /></td>
</tr>
</table>
<input type="button" name="show" id="showEvents" style="width:auto" value="Show All Events" />
<p>
<input type="submit" value="Create" />
</p>