【发布时间】:2023-03-05 05:39:01
【问题描述】:
我无法在 Android 2.2.1 的输入上覆盖选定的文本。
以下example 选择输入文本,但maxlength 属性阻止写入新值。
如果我删除 maxlength,新值将连接在前一个值之后。
编辑:如果我使用 click 事件而不是 keyup example 工作正常。
【问题讨论】:
标签: javascript android jquery html mobile
我无法在 Android 2.2.1 的输入上覆盖选定的文本。
以下example 选择输入文本,但maxlength 属性阻止写入新值。
如果我删除 maxlength,新值将连接在前一个值之后。
编辑:如果我使用 click 事件而不是 keyup example 工作正常。
【问题讨论】:
标签: javascript android jquery html mobile
试试这个
$( '#current1' ).keyup( function(e) {
$( '#current2' ).focus();
$( '#current2' ).selectRange( 0, 1 );
});
$.fn.selectRange = function(start, end) {
var e = document.getElementById($(this).attr('id')); // I don't know why... but $(this) don't want to work today :-/
if (!e) return;
else if (e.setSelectionRange) { e.focus(); e.setSelectionRange(start, end); } /* WebKit */
else if (e.createTextRange) { var range = e.createTextRange(); range.collapse(true); range.moveEnd('character', end); range.moveStart('character', start); range.select(); } /* IE */
else if (e.selectionStart) { e.selectionStart = start; e.selectionEnd = end; }
};
【讨论】: