iPad Safari does not fire blur event

2019-04-04 00:41发布

问题:

I have an html input text element in my application with jQuery blur event handler:

$('#textBox').blur(function () { console.log('blur'); })

When I click on a page area out of the textbox, desktop browsers fire this event, but iPad Safari does not. And neither the keyboard nor the cursor does not disappear. Are there any ways to "enable" the blur event ?

回答1:

By design, a tap away will remove the hover state but the textbox will remain focused.

Safari Web Content Guide should help you develop for Safari on IOS devices.



回答2:

Workaround (albeit not recommended): https://codepen.io/kevinfarrugia/pen/rKpRBL

document.getElementById("container").addEventListener("click", () => {
  document.getElementById("container").focus();
});