【发布时间】:2020-12-11 13:40:13
【问题描述】:
在电脑上运行良好。在计算机上输入单词并按空格键后,该单词将被包裹在一个框中,您可以选择将其删除。在手机上按下空格键后什么也没有发生。它也不限制在手机上使用 5 个单词。
工作 jsfiddle:http://jsfiddle.net/1hco43vr/
$('#box a').on('click', function() {
$(this).parent().parent().remove();
console.log('remove disabled');
if ($('#box ul li').length <= 5) {
$('#type').prop('disabled', false);
}
});
}
$('#type').keypress(function(e) {
if (e.which == 32) { //change to 32 for spacebar instead of enter
var tx = $(this).val();
if ($('#box ul li').length > 5) {
$(this).val('');
console.log('add disabled');
$('#type').prop('disabled', 'disabled');
} else {
if (tx) {
$(this).val('').parent().before('<li><span>' + tx + '<a href="javascript:void(0);">x</a></span></li>');
closer();
}
}
}
});
【问题讨论】:
-
当我将 229 添加到代码中时,它对手机上的
keypress没有任何作用:$('#type').keypress(function(e) { if (e.which == 32 || e.which == 229)但是当我将其更改为keyup$('#type').keyup(function(e) { if (e.which == 32 || e.which == 229)它在计算机上运行良好但在手机上,每个按钮都会触发该功能,而不仅仅是空格键。为什么会这样? -
另外
https://unixpapa.com/js/testkey.html说我的三星手机上的所有按键都产生keyCode 229。我不明白。任何帮助将不胜感激。
标签: javascript jquery textbox