在我的应用程序中,我有一个文本区域,用户无法在其中删除使用退格键或使用 IE9 中的删除键输入的字符。这适用于 Chrome。
我有以下代码
$('textarea').live('keydown', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
var currentIndex = getCaret($(this).get(0))
selectText($(this), currentIndex);
return false;
}
});
});
我使用jQuery.highlighttextarea.js来突出显示图案上的单词。 我不确定是否需要修改 jQuery.highlighttextarea.js 来处理退格键或删除。 请推荐
我确实使用过它
我确实使用过它
if (e.which == 9) {
var currentIndex = getCaret($(this).get(0))
selectText($(this), currentIndex);
return false;
}
if (e.which == 8 || e.which == 46) {
return false;
}
但是现在退格键或删除不起作用
最佳答案
键码 9 是 tab
。检查这里:http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
您需要 8
和 46
,所以类似于:
if (e.which == 8 || e.which == 46) return false;
关于javascript - 退格键和删除按钮不会删除 IE 上文本区域中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17451078/