Internet explorer 在IE浏览器中,当用户进行编辑时,防止光标移动到输入框的末尾
在我的anuglar 7应用程序中,在所有文本输入字段中,我都包含了一个方法,可以将用户键入的任何文本的值更改为大写。在IE浏览器中,当用户对输入的文本进行编辑时,光标会自动移动到输入框的末尾,而不是停留在原处 我怀疑导致问题的方法是:Internet explorer 在IE浏览器中,当用户进行编辑时,防止光标移动到输入框的末尾,internet-explorer,angular7,uppercase,Internet Explorer,Angular7,Uppercase,在我的anuglar 7应用程序中,在所有文本输入字段中,我都包含了一个方法,可以将用户键入的任何文本的值更改为大写。在IE浏览器中,当用户对输入的文本进行编辑时,光标会自动移动到输入框的末尾,而不是停留在原处 我怀疑导致问题的方法是: oninput="this.value = this.value.toUpperCase()" 我在chrome浏览器中没有这个问题。我能做些什么来防止IE浏览器出现这种情况 输入字段的我的html代码: <input
oninput="this.value = this.value.toUpperCase()"
我在chrome浏览器中没有这个问题。我能做些什么来防止IE浏览器出现这种情况
输入字段的我的html代码:
<input
type="text"
class="form-control col-lg-7"
id="primary-email"
formControlName="primaryEmail"
pattern="[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?"
placeholder="example@domain.com"
required
[ngClass]="{ 'is-invalid': submitted && f['primaryEmail'].errors }"
[(ngModel)]="primaryEmail"
oninput="this.value = this.value.toUpperCase()"
/>
由于怀疑,问题来自
oninput="this.value = this.value.toUpperCase()"
我为解决这个问题所做的更改(在谷歌搜索之后)是在我的TS文件中创建一个方法:
makeUpperCase(e) {
const cursorStart = e.target.selectionStart;
const cursorEnd = e.target.selectionEnd;
e.target.value = e.target.value.toUpperCase();
e.target.setSelectionRange(cursorStart, cursorEnd);
}
然后在HTML文件中,将有问题的行替换为:
(input)="makeUpperCase($event)"
希望这能帮助其他遇到IE类似问题的人。感谢您发布此问题的解决方案。您可以将您的答案标记为已接受的答案。它可以在将来帮助其他社区成员解决类似的问题。谢谢你的理解。