[英]Is there any way to prevent input type=“number” getting more than one dot values?
[英]Prevent on getting 0 in input tag type=number
我存儲購物車表的 html 元素。 我無法阻止在輸入 id="qtyInput" 上獲得 0 值
這是javascript代碼...
var qtyInput = '<input id="qtyInput" class=" text-center" type="number" min="1" oninput="this.value = Math.abs(this.value)" style="width:50px;" id="qty_value" name="qty_value" value="' + productQty + '"><input type="hidden" id="productId" value="' + productId + '">'
cartHtml += '<tr><td><img src="../admin/img/product_images/' + productImg + '" style="width:50px"/></td><td>' + productName + '</td><td>' + productPrice + '</td><td>' + productTotal + '</td><td>' + qtyInput + '</td><td>' + deleteBtn + '</td></tr>';
阿賈克斯代碼
function fetchCartData() {
$.ajax({
url: 'ajax_calls/fetch-cart.php',
type: 'GET',
dataType: 'json',
success: function(response) {
var cartHtml = "";
if (response.data.length > 0) {
$.each(response.data, function(key, item) {
productId = item[0];
var productImg = item[4];
var productName = item[1];
var productQty = item[2];
var productPrice = parseFloat(item[3]).toFixed(2);
var productTotal = parseFloat(item[3] * item[2]).toFixed(2);
var deleteBtn = item[5];
var qtyInput = '<input id="qtyInput" class=" text-center" type="number" min="1" oninput="this.value = Math.abs(this.value)" style="width:50px;" id="qty_value" name="qty_value" value="' + productQty + '"><input type="hidden" id="productId" value="' + productId + '">'
cartHtml += '<tr><td><img src="../admin/img/product_images/' + productImg + '" style="width:50px"/></td><td>' + productName + '</td><td>' + productPrice + '</td><td>' + productTotal + '</td><td>' + qtyInput + '</td><td>' + deleteBtn + '</td></tr>';
});
$("#cart-items-table").html(cartHtml);
$("#sub-total").html(response.subTotal.toFixed(2));
$("#grand-total").html(response.grandTotal.toFixed(2));
// event binding for updateQty function
$('#cart-items-table').on('keyup', '#qtyInput', function() {
var pId = $(this).siblings("#productId").val();
var qty = $(this).val();
updateQty(pId, qty);
});
} else {
cartHtml = '<div class="text-center"> <h4> Your Cart is Empty</h4></div>';
$("#cart-table-html").html(cartHtml);
}
$("#cart_qty").html(response.totalCartQty);
$("#cart_qty1").html(response.totalCartQty);
} // /success
}); // /ajax
}
我希望你能幫助我。 非常感謝
<input type="number" min=1 max=1000>
當然,它會起作用。 嘗試一下
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.