通过确认对话框防止单击事件,然后继续操作

时间:2019-07-05 02:19:06

标签: javascript jquery html css alertify

我正在尝试在删除之前创建一个对话框,所以我添加了e.preventDefault()来直接删除,但是当我进入YES函数时,我想模拟该函数以继续它的click事件并返回true和e.preventDefault()为false。 如何继续点击事件以进行操作?

<script type="text/javascript">
    $(function() {
        $('#delete_registry').on('click', function(e) {

            e.preventDefault();

            alertify.confirm('Delete Registry', 'Are you sure you want to delete your registry, all data will be lost', function() {
                    console.log('deleting information');
                    this.close();
                    return true;
                }, function() {
                    this.close();
                    return false;
                })
            .setHeader(header)
            .setting({
                'closable': false, 
                'resizable': true,
                'labels': {'ok': 'Yes', 'cancel': 'No'}
            });
        });
    });
</script>

1 个答案:

答案 0 :(得分:1)

尝试简单

$('button').click(function(){
   if(confirm('are you sure?')){
    return alert('Deleted');
   }
   return alert('Not Deleted');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>Delete</button>