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
Add a ment  | 

3 Answers 3

Reset to default 4

Maybe 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