我有一个带有登录表单的移动模板,它是基于ajax/url hash的浏览.如果在iphone上用户点击iphone键盘上的"go"按钮,ajax会对其进行身份验证/登录,然后将下一页加载到另一个div中,并隐藏当前的登录表单div.
问题是,在iphone上键盘仍然弹出.无论如何通过javascript取消对文本框元素的聚焦?
Xin*_*nt0 69
使用该blur()方法或尝试将焦点设置在链接等其他元素上.
小智 17
这就是我.blur()不想成为我朋友的时候所用的
function blurAll(){
var tmp = document.createElement("input");
document.body.appendChild(tmp);
tmp.focus();
document.body.removeChild(tmp);
}
Run Code Online (Sandbox Code Playgroud)
小智 9
如果你只想模糊没有目标的东西,你可以blur()调用activeElement:
document.activeElement.blur();
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以在 javascript 中使用 element.disabled 参数。
例子:
<!DOCTYPE html>
<html>
<body>
Name: <input type="text" id="myText">
<p>Click the button to unfocus the text field.</p>
<button onclick="myFunction()">Unfocus input</button>
<script>
document.getElementById("myText").focus();
function myFunction() {
document.getElementById("myText").disabled = true;
document.getElementById("myText").disabled = false;
}
</script>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
`
| 归档时间: |
|
| 查看次数: |
61736 次 |
| 最近记录: |