【发布时间】:2018-01-06 19:36:05
【问题描述】:
我有一个 9x9 的 html 表格,里面有输入元素,编码数独板。
我使用 jQuery 的 .keypress 方法来验证用户输入,然后将焦点切换到下一个框:
// Only allow numbers from 1-9 (49-57), the 0-key (48) to tab, and the 'Enter' key to submit (13)
$('.box').keypress(function(event) {
// Check for 'Enter' key
if (event.which === 13) {
return event.which;
// Check for digits 1-9
} else if (event.which >= 49 && event.which <= 57) {
if ($(this).parent().is('td:last-child')) {
$(this).closest('tr').next().children().first().find('.box').focus();
} else {
$(this).parent().next().find('.box').focus();
}
return event.which;
// Check for 0-key
} else if (event.which === 48) {
if ($(this).parent().is('td:last-child')) {
$(this).closest('tr').next().children().first().find('.box').focus();
} else {
$(this).parent().next().find('.box').focus();
}
return false;
// Check for other invalid keys
} else {
return false;
}
});
这在台式机/笔记本电脑上运行良好,但在 iOS 上,来自 .keypress 方法的返回值不会显示在板上,除了最后一个框(底部,右侧)。
我使用jQuery 3.2.1 slim 和iOS 9.3.5 Chrome/Safari。
谁能帮忙?
谢谢!
【问题讨论】: