我想驗證兩個文本框的數據。我已經提交了這個文本框。Jquery數學運算不起作用
<div class="col-md-3">
<label for="SubmittedAmountTextBox">Total Submitted Amount</label>
<Everest:AmountTextBox runat="server" ID="SubmittedAmountTextBox" TriggerDenomination="True" autocomplete="off" CssClass="loan-amount-input submitted-amount"></Everest:AmountTextBox>
<asp:RequiredFieldValidator runat="server" ID="SubmittedAmountTextBoxRequiredFieldValidator" Display="Dynamic"
ErrorMessage="Required" ControlToValidate="SubmittedAmountTextBox" CssClass="alert alert-error" Style="padding: 5px;" SetFocusOnError="true" />
</div>
另一個來自usercontrol的文本框。
<div class="col-sm-2">
<asp:TextBox runat="server" ID="LoanCollectionBalanceTextBox" CssClass="form-control input-sm" data-bind-property="CollectionBalance" />
</div>
ajax調用獲取文本框的所有數據。我只是試圖通過bootbox警報,如果SubmittedAmountTextBox
輸入大於LoanCollectionBalanceTextBox
。
我的jQuery函數用於驗證:
function validateAmount() {
var sbmtAmount = $('#SubmittedAmountTextBox').val();
console.log(sbmtAmount);
var loancollecBlnce = $('#LoanCollectionBalanceTextBox').val();
if (sbmtAmount > loancollecBlnce) {
alert(sbmtAmount);
alert(loancollecBlnce);
debugger;
//bootbox.alert("Submitted amount is higher then Collection Balance")
$("#SaveButton").attr('disabled', 'disabled');
} else {
$("#SaveButton").attr('disabled', false);
}
}
和SubmittedAmountTextBox
$('#SubmittedAmountTextBox').on('blur', function (evt) {
var checkedValue = $('input[id*=loanTypeCheck]:checked').val();
if (checkedValue === "Cash") {
$(this).trigger('showDeno', [$(this)]);
} else if (checkedValue === "Dharauti") {
validateAmount();
}
});
模糊事件和怪異的一部分是它不驗證,如果SubmittedAmountTextBox
>LoanCollectionBalanceTextBox
。假設LoanCollectionBalanceTextBox
是12500,如果我輸入更多,那麼它會引發警報。如果我輸入100,它不會因爲12500> 100,但如果我輸入200,300之間的任何數值,它確實會拋出錯誤。我到處搜索無法得到這個。
,因爲你在不知不覺中對字符串進行操作,而「12500」 <「200」詞彙 –
@JaromandaX我沒有得到你sir..I我仍然掛在學習曲線左右。 – OLDMONK
['.val()'](http://api.jquery.com/val/)返回一個字符串。首先必須將值轉換爲數字(['parseInt()'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)或['parseFloat( )'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)) – Andreas