我有一个带有 Bootstrap 元素的按钮。
<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>';
它有一个 css 属性,我将它涂成红色。
当用户点击删除按钮时,会出现一个 JavaScript 确认。
问题是每当我点击取消时,按钮就会被聚焦。如何删除焦点按钮?
这是 jQuery 代码:
<script>
$(document).on('click', ':not(form)[data-confirm]', function(e) {
if( !confirm($(this).data('confirm')) ) {
e.stopImmediatePropagation();
e.preventDefault();
}
});
</script>
最佳答案
也许你可以尝试 blur()
按钮?
<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>
关于javascript - 关闭javascript确认框后如何从按钮上移除焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53655873/