[英]How to fire an event only when text is entered in an input box but not removed?
當將數字輸入到9 * 9
Sudoku網格(或從中刪除)時,以下代碼片段觸發警報事件。
$('table tr td input').on({"input": function () {
var cell = $(this).val();
if (!$.isNumeric(cell)) {
alert("Please enter only numbers from 1 to 9");
}
}});
但是,如何在刪除文本時刪除警報消息? 僅當輸入數字時才必須觸發它。
更改
if (!$.isNumeric(cell)) {
至
if (cell && !$.isNumeric(cell)) {
我將執行以下操作。
$('table tr td input').on({"input": function () {
var cell = $(this).val();
if (cell.length > 0 && !$.isNumeric(cell)) {
alert("Please enter only numbers from 1 to 9");
}
}});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.