繁体   English   中英

在尝试输入介于两者之间的值时,光标会跳到输入行的末尾

[英]Cursor jumps to the end of the input line while try to enter the value in between

我这样做是为了避免在第一个位置和输入字段中的特殊字符出现空格。 现在工作正常。 但是光标在尝试在第一个位置或中间位置输入时移到末尾,因为我将str分配给e.target.value。 这仅在野生动物园浏览器中发生。 这是我的代码。

var inputValue = e.target.value; // get input value
let str = inputValue;
str = str.replace(/^\s+/, '');    
str = str.replace(/[^a-zA-Z\s]/g, ""); 
e.target.value = str;

谁能告诉我解决方案?

请尝试以下操作:

var inputValue = e.target.value; // get input value
document.getElementById("yourInputId").value = inputValue.replace(/^\s+/, '').replace(/[^a-zA-Z\s]/g, "");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM