javascript - Focus event for button doesn't fire on iPad
问题描述
I want to add a bootstrap popover to my site. It should show up, when the user pushes a button by using the focus event. This works on the Desktop, but not on the iPad. It seems like Safari on iOS doesn't raise the focus event for buttons altogether.
As a workaround, I replaced the button with an a tag. This does work, but gives some other issues like a lack of the disabled state without adding a specific class.
<a class="btn btn-outline-secondary" id="ap-btn-selectColor" data-toggle="popover" role="button">
<i class="fa" style="background-color: rgb(140, 181, 255); width: 16px" id="ap-fgColorSelection"> </i>
</a>
<button type="button" class="btn btn-outline-secondary" id="ap-btn-selectBorderColor" data-toggle="popover">
<i class="fa" style="background-color: rgb(0, 51, 142); width: 16px" id="ap-bdColorSelection"> </i>
</button>
$('[data-toggle="popover"]').popover({
content: function () {
return $someElement;
},
placement: 'auto',
html: true,
trigger: 'focus'
});
In my example, the popover works for the first element, but not for the second.
Is there a way to enable the focus event for buttons on iOS?
解决方案
解决方案非常简单。您根本无法button
在 iOS 设备上使用 a,因为它没有焦点事件。相反,您应该使用带有有效设置的a
标签。role="button"
tabindex
<a role="button" id="ap-btn-selectBorderColor" class="btn btn-outline-secondary" data-toggle="popover" tabindex="1">
<i class="fa" style="background-color: rgb(0, 51, 142); width: 16px" id="ap-bdColorSelection"> </i>
</a>
推荐阅读
- visual-studio-code - vscode/LSP:使用断点调试 vscode 扩展
- javascript - 倒计时并在发生时更改变量
- sql - 将多行连接成一行并按日期分组
- java - 基于条件的字符串验证
- flutter - 在 TabBarView 中颤动 PageView:滚动到页面末尾的下一个选项卡
- android - Dagger 2 组件未在 android studio 中生成
- stata - 如何使 x 轴标签出现在刻度之间
- shell - GItLab CI 给出 curl: (7) 无法连接到 localhost 端口 8090: Connection denied
- html - 如果我尝试从 css 文件上传图像,则图像不会出现在我的部分中,但是当我从 html 尝试时它可以工作
- javascript - 循环测试是一个好习惯吗?