[英]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.