admin管理员组文章数量:1329040
I have a button with a bootstrap element on it.
<button title="delete" type="button" class="btn btn-default btn-sr" data-confirm="Are you sure to delete this item?"><span class="glyphicon glyphicon-trash white"></span></button></a>';
It has a css property which I color it red.
When user clicks the delete button, a JavaScript confirmation will e out.
The problem is whenever i click cancel, the button will be focused. How do I remove the focused button?
Here is the jQuery code:
<script>
$(document).on('click', ':not(form)[data-confirm]', function(e) {
if( !confirm($(this).data('confirm')) ) {
e.stopImmediatePropagation();
e.preventDefault();
}
});
</script>
I have a button with a bootstrap element on it.
<button title="delete" type="button" class="btn btn-default btn-sr" data-confirm="Are you sure to delete this item?"><span class="glyphicon glyphicon-trash white"></span></button></a>';
It has a css property which I color it red.
When user clicks the delete button, a JavaScript confirmation will e out.
The problem is whenever i click cancel, the button will be focused. How do I remove the focused button?
Here is the jQuery code:
<script>
$(document).on('click', ':not(form)[data-confirm]', function(e) {
if( !confirm($(this).data('confirm')) ) {
e.stopImmediatePropagation();
e.preventDefault();
}
});
</script>
Share
Improve this question
edited Dec 6, 2018 at 16:42
D4V1D
5,8493 gold badges33 silver badges68 bronze badges
asked Dec 6, 2018 at 16:37
KingJKingJ
1231 silver badge7 bronze badges
2
- look at this: > stackoverflow./questions/2520650/… – Ali Mardan Commented Dec 6, 2018 at 16:40
- 1 If you plan to support the blind and those needing ARAI tags, then you should leave the focus where it was before opening the dialog. Otherwise it gets confusing for the user not knowing where the focus was put. – Intervalia Commented Dec 6, 2018 at 16:42
3 Answers
Reset to default 4Maybe could you try to blur()
the button?
<script>
$(document).on('click', ':not(form)[data-confirm]', function(e) {
if( !confirm($(this).data('confirm')) ) {
e.stopImmediatePropagation();
e.preventDefault();
$(this).blur(); // to make the focus disappear
}
});
</script>
$(this).blur();
over
document.activeElement.blur()
$(this).blur();
removes the focus
本文标签: jqueryHow to remove focus from button after closing javascript confirm boxStack Overflow
版权声明:本文标题:jquery - How to remove focus from button after closing javascript confirm box - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742222329a2435522.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论