gpt4 book ai didi

android - Android Chrome 中的 Jquery 错误

转载 作者:太空宇宙 更新时间:2023-11-03 11:04:52 25 4
gpt4 key购买 nike

我有下面的 jquery,它在桌面浏览器上运行良好,当我将它加载到 android 移动 chrome 上并开始输入时,第二个字母在第一个字母之前,其他字母在第二个字母之后。

Here is an image how its working...

谁能帮我解决这个问题?

 $("#textbox").on('input', function(evt) {
if(this.lengh == 0) return $(this);

var input = $(this);
var start = input[0].selectionStart;
$(this).val($(this).val().replace(/[^a-zA-Z0-9 +:%=\\/-]/gi,""))
$(this).val(function (_, val) {
return val.toUpperCase();
});
input[0].selectionStart = input[0].selectionEnd = start;
});

最佳答案

问题是,在 Android 中,selectionStart 为零。

用手机测试:http://www.vixed.it/st/34947263/

$("#textbox").on('input', function(e) {
e.preventDefault();
var input = $(this);
var start = input[0].selectionStart;
var inputTextChanged = input.val().replace(/[^a-zA-Z0-9 +:%=\\/-]/gi,"").toUpperCase();
input.val(inputTextChanged);
if (start>=1) input[0].selectionEnd = start;
});

关于android - Android Chrome 中的 Jquery 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34947263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com