我想弄清楚在移动Safari,Android浏览器和Android的Firefox(“Fennec”)中看到的效果是一个错误或预期的行为。基本上,问题是在某些情况下,即使<input>
元素最初未被用户点击,<input>
元素也可以在某些情况下接收键盘焦点。这是一个错误?点击一个元素可能会导致不同的元素接收键盘焦点
这里是一个可再现的测试案例:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, user-scalable=no">
<style>
#screenCover {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.3);
z-index: 1;
}
#newItemInput {
position: absolute;
width: 200px;
height: 20px;
}
</style>
</head>
<body>
<div id="screenCover"></div>
<input id="newItemInput" type="text">
<script type="text/javascript" language="JavaScript">
var screenCoverEl = document.getElementById("screenCover"),
newItemInputEl = document.getElementById("newItemInput");
newItemInputEl.value = String(navigator.userAgent);
screenCoverEl.addEventListener("touchend", function (event) {
// Move the <input> element in the way.
newItemInputEl.style.top = (event.changedTouches[0].clientY - 10) + "px";
newItemInputEl.style.left = (event.changedTouches[0].clientX - 10) + "px";
// Hide the screen cover. Note that the screen cover was the original target of the tap.
screenCoverEl.style.display = "none";
}, false);
newItemInputEl.addEventListener("click", function (event) {
this.setSelectionRange(0, this.value.length);
}, false);
</script>
</body>
</html>
在移动浏览器
或者直接:
http://fiddle.jshell.net/f7TKc/2/show/
在这个例子中,屏幕盖位于上方该文档,但在touchend
上,屏幕封面被隐藏,并移动了元素<input>
到用户点击屏幕盖的地方。在Mobile Safari,Android Browser和Fennec 13.0b1中,<input>
元素莫名其妙地收到了键盘焦点。
我不能在较新版本的Fennec中测试它,因为它在模拟器中崩溃。
这是一个错误或预期的行为?
HTTP ://code.google.com/p/android/issues/detail?id = 6721? – Slartibartfast