为什么在iOS Safari Mobile(iPhone / iPad)中未启用模糊事件? [英] Why is blur event not fired in iOS Safari Mobile (iPhone / iPad)?
问题描述
我有两个事件处理程序绑定到一个定位标记:一个用于焦点和模糊。
I've two event handlers bound to an anchor tag: one for focus and blur.
处理程序在桌面上触发,但在iphone和ipad中,正确启动。如果我在定位标记外单击,模糊不会被触发(仅当我单击页面中的其他表单元素时才会触发模糊):
The handlers fire on desktop, but in iphone and ipad only focus is fired correctly. Blur is not fired if I click outside the anchor tag (blur fires only when I click some other form elements in the page):
$("a").focus(function(){
console.log("focus fired");
});
$("a").blur(function(){
console.log("blur fired");
});
HTML:
HTML:
<html>
<form>
<a href="#">test link</a>
<div>
<input type="text" title="" size="38" value="" id="lname1" name="" class="text">
</div>
<div style="padding:100px">
<p>test content</p>
</div>
</form>
</html>
推荐答案
如果锚点附有任何事件,在iOS上它导致锚点被置于悬停状态,并聚焦。点击即可消除悬停状态,但链接保持聚焦状态。这是设计。要正确控制iOS上的应用程序,您需要实现基于触摸的事件并对那些应用程序做出反应,而不是桌面应用程序。
If an anchor has any events attached, the first tap on it in iOS causes the anchor to be put into the hover state, and focused. A tap away removes the hover state, but the link remains focused. This is by design. To properly control an application on iOS, you need to implement touch-based events and react to those instead of desktop ones.
在iOS中的WebKit中使用Javascript事件的完整指南。
这篇关于为什么在iOS Safari Mobile(iPhone / iPad)中未启用模糊事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!