我试图禁用自动填充提示,提示我输入页面上的用户名和密码字段,并在现有代码中引入了以下内容后非常成功。 readonly onfocus="myFunc(this.id)
。尽管我最初尝试autocomplete="false"
或autocomplete="off"
并没有任何帮助,但我只是让它在那里。
<tr>
<td align="right">Username:</td>
<td><input type="text" name="username" class="input" MAXLENGTH=8 size="25" autocomplete="false" id="username " readonly onfocus="myFunc(this.id)" onKeyPress="return submit(event)"></td>
</tr>
关键是上面的代码确实有助于禁用[大多数浏览器]的自动填充功能,但是当我去单击空白文本框以键入用户名时,该文本框为空并且不会从键盘上获取任何输入(好像它仍然是
readonly
-仅在IE11中可见的问题)。单击时将应用颜色更改。调用的JS函数如下。function myFunc(x) {
//x.removeAttribute('readonly');
//x.style.background = "yellow";
document.getElementById(x).removeAttribute("readonly");
document.getElementById(x).style.background = "yellow";
}
现在在文本框中单击第二次即可输入。有人可以让我知道如何在IE中修复此问题。
最佳答案
这已经在这里得到回答:Readonly input box bug in Internet Explorer
尝试document.getElementById(x).select()
,它将光标移回输入。
关于javascript - html中的readonly属性不能与removeAttribute一致地工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38988343/