[英]how to prevent iOS safari from focusing new element?
When I remove a button on click and place new button at the same location, safari on iphone sets the focus state on the new button.当我在单击时删除按钮并将新按钮放置在同一位置时,iphone 上的 safari 将焦点状态设置在新按钮上。 This results in a focused button while the user hasn't clicked the new button.
当用户没有点击新按钮时,这会导致一个焦点按钮。 How can I prevent iOS safari from focusing my new element?
如何防止 iOS Safari 聚焦我的新元素?
This behavior does not occur on my android device with chrome.这种行为不会发生在我的带有 chrome 的 android 设备上。 The only answers I could find about iOS safari are where the focused state is not removed after click.
我能找到的关于 iOS safari 的唯一答案是点击后没有删除焦点状态。 I have tried preventDefault, stopPropagation but it is not working.
我尝试过 preventDefault、stopPropagation 但它不起作用。
Fiddle similar to my situation.小提琴类似于我的情况。 This does a direct replace while my code replaces after successfully receiving content from get call.
这会在我的代码从 get 调用成功接收内容后进行替换时进行直接替换。
<div class="container">
<a class="btn btn-info">first button</a>
</div>
<script>
$(".btn").click(function () {
$(this).remove();
$('.container').append('<a class="btn btn-info">second button</a>')
});
</script>
https://jsfiddle.net/puymn180/2/ https://jsfiddle.net/puymn180/2/
Fix will probably be difficult but workaround would be acceptable.修复可能会很困难,但解决方法是可以接受的。
I found a workaround for this issue by adding the button asynchronously.我通过异步添加按钮找到了解决此问题的方法。
setTimeout(function () {
$('.container').append('<a class="btn btn-info">second button</a>');
}, 0);
This does not solve the problem where a button keeps focus without replacing the button' element.这不能解决按钮保持焦点而不替换按钮元素的问题。 (where most people are looking for)
(大多数人正在寻找的地方)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.