Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery单击事件_Jquery - Fatal编程技术网

jquery单击事件

jquery单击事件,jquery,Jquery,我的网站上有一个删除按钮,我想在其中添加一个确认框。我在JQuery中编写了以下代码,但是如果用户确认删除,我不确定如何继续页面加载。e、 g.我应该在if语句中添加什么来反转默认值 $(".delete").click(function(e){ e.preventDefault(); if (confirm('Are you sure you want to delete this?')) { NEED SO

我的网站上有一个删除按钮,我想在其中添加一个确认框。我在JQuery中编写了以下代码,但是如果用户确认删除,我不确定如何继续页面加载。e、 g.我应该在if语句中添加什么来反转默认值

$(".delete").click(function(e){
            e.preventDefault(); 

            if (confirm('Are you sure you want to delete this?')) {
                 NEED SOMETHING IN HERE TO CONTINUE WITH THE LOADING OF THE PAGE

            }
        });
感谢您。preventDefault()与simple
return false
具有相同的功能,因此您可以执行此操作以达到相同的效果:

$(".delete").click(function(e){
    // Will continue if the user clicks 'Yes'
    return confirm('Are you sure you want to delete this?');
});
不知道你想做什么,但这应该能回答你的问题

请注意,此函数无法停止页面加载,因为调用此函数时,页面已加载。因此,如果您需要更具体的答案,请举例说明您正在尝试做什么。

只需更改逻辑即可

$(".delete").click(function(e){
    if (!confirm('Are you sure you want to delete this?')) {
        e.preventDefault();           
    }
});