[英]Require field if shown in javascript
我有一個表格,如果有人單擊鏈接,它將為他們打開輸入以填寫他們的信用卡號。 我正在嘗試這樣做,以便如果顯示此表單並單擊添加,它將告訴他們需要CC#。 如果他們單擊“取消”,它將僅隱藏表單。
當用戶單擊鏈接時,此代碼顯示表單
function lnkAddCc_Click(sender, args) {
//this is overkill, but just to make sure inputs are clean
$('#addCCRow').find('input').each(function () { (this).value = ''; });
$('#<%= fullCcNumber.ClientID %>').val('');
$('#addCCRow').hide();
$('#addCCLabel').hide();
$('#addCCRow').show();
}
當他們單擊取消時,此代碼將關閉表單
function btnCancel_Click(sender, args) {
args.set_cancel(true);
$('#addCCRow').find('input').each(function () { (this).value = ''; });
$('#<%= fullCcNumber.ClientID %>').val('');
$('#addCCRow').hide();
$('#addCCLabel').show();
var validate = $('#aspnetForm').validate();
validate.resetForm();
我不能在我的驗證器上使用
<tr class="AltRow" id="addCCRow" style="display: none">
<td><label style="color: black;">Credit, Debit or ATM Card Number:</label></td>
<td style="text-align: right; width: 100%;">
<input ID="newCard0" MaxLength="4" size="6" onkeyup="CopyCardInput(this)" /> -
<input ID="newCard1" MaxLength="4" size="6" onkeyup="CopyCardInput(this)" /> -
<input ID="newCard2" MaxLength="4" size="6" onkeyup="CopyCardInput(this)" /> -
<input ID="newCard3" MaxLength="4" size="6" onkeyup="CopyCardInput(this)" /><br />
因為它要求它是否可見。 我如何才能僅在可見時要求它?
只需將一個對象傳遞給validate選項,並覆蓋ignore選項:
var validate = $('#aspnetForm').validate({
ignore: ""
});
validate.resetForm();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.