我有一個發票表單和一個jquery函數。 在發票中,如果我輸入的數量大於可用數量,那麼我必須提醒用戶。jquery事件不能正常工作
我的問題是:讓最大數量是5,如果我輸入數據爲7(單個數字>最大可用數量),那麼我的代碼工作正常。但是,如果我輸入兩個digigist號碼,例如。 17(兩個digists>最大可用數量),那麼我的警報框不會來。 我的意思是onkeyup我的功能只能使用單個數字。
我該如何讓它發生?請幫忙。
$('input[name="quantity"]').keyup(function()
{
//problem is here
var $tr = $(this).closest("tr");
var unitprice = $tr.find('input[name^="unitprice"]').val();
var q = $tr.find('input[name^="quantity"]').val();
var cq = $tr.find('input[name^="checkquantity"]').val();
if(q>cq)
{
alert("Error: Quantity value exceeds then available quantity..Max Quantity is "+cq);
//this works fine only if single digit is entered in textbox quantity
}
//----below are some other stuffs -these are working fine
$tr.find('input[name^="sprice"]').val($(this).val() * unitprice);
var totalPrice = 0;
$('input[name="sprice"]').each(function()
{
totalPrice += parseFloat(this.value);
$('[name=subtotal]').val(totalPrice);
});
});
--------------
------------
// Form containing the above textboxes
<input type="submit" id="submitbtnId" value="Save"/>`
非常感謝。 –