Javascript Android don'上texarea中插入符号的控制代码;I don’我没有按预期工作
我尝试使用以下代码:Javascript Android don'上texarea中插入符号的控制代码;I don’我没有按预期工作,javascript,android,jquery,webkit,cursor,Javascript,Android,Jquery,Webkit,Cursor,我尝试使用以下代码: function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { //input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) {
function setSelectionRange(input, selectionStart, selectionEnd) {
if (input.setSelectionRange) {
//input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
range.select();
}
}
function fakeMobileEntry() {
if (isTouch()) {
// delay worked while experimenting
self.oneTime(10, function() {
clip.val(command);
self.oneTime(10, function() {
clip.caret(position);
});
});
}
}
它可以在桌面上正常工作,但不能在Android(2.3)上正常工作。当我试图删除字符时,插入符号不会停留在结尾,而是在单词的中间。p>
。代码使用此函数简单地将光标和命令映射到插入符号
function fakeMobileEntry() {
if (isTouch()) {
clip.val(command).caret(position);
}
}
对于测试,isTouch返回true。任何人在android(旧webkit)中有插入符号问题我使用了以下代码:
function setSelectionRange(input, selectionStart, selectionEnd) {
if (input.setSelectionRange) {
//input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
range.select();
}
}
function fakeMobileEntry() {
if (isTouch()) {
// delay worked while experimenting
self.oneTime(10, function() {
clip.val(command);
self.oneTime(10, function() {
clip.caret(position);
});
});
}
}
在keydown for backspace中,我将return设置为true(在我的代码中,所有keydown快捷键都返回false)