Input type text chỉ cho phép nhập số, html text input allow only numeric input? có bạn nào biết cách làm sao chỉ cho phép nhập số vào thẻ input có type text không bạn? Mã: <input type="text" class="quantity-input input-text qty text" title="Số lượng cần mua" name="quantity" value=""> Cái input type number mặc định của nó cùi bắp quá, mình mún tự chế cái thẻ input text chỉ cho phép nhập số không cho nhập ký tự và dấu , . vào đó luôn thì làm như thế nào bạn nào biết cho mình xin đoạn code nhé xử lý trong javascript hay jQuery gì đó.
Của bạn đây nhé: HTML: <input type="text" class="quantity-input input-text qty text" onkeypress="return isNumberKey(event)" title="Số lượng cần mua" name="quantity" value=""> HTML: //cho phép cut copy paste drag drop trong thẻ input $(document).ready(function() { $('.quantity-input').bind("cut copy paste drag drop", function(e) { e.preventDefault(); }); }); function isNumberKey(e) { var charCode = (e.which) ? e.which : e.keyCode; if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; }