How to confirm clicking on a link using jQuery

后端 未结 5 1734
攒了一身酷
攒了一身酷 2021-02-13 15:23

I have many links in a HTML-table, which delete corresponding row, when clicked (calling a PHP-script via GET parameter).

They all have a class delete_row

相关标签:
5条回答
  • 2021-02-13 15:54

    Very simple and effective one line solution without using jquery:

    <a href="to/your/path" onclick="return confirm('Are you sure you want to delete?');">Delete</a>
    
    0 讨论(0)
  • 2021-02-13 15:58

    you can use preventDefault method of the event object in the handler function:

    jQuery('.delete_row').click(function(event){
         if(!confirm('Really Delete?')){
             event.preventDefault();
         }
    })
    
    0 讨论(0)
  • 2021-02-13 15:59

    I think there is a error!

    Use this:

    $('.delete_row').click(function(){
        return confirm("Are you sure you want to delete?");
    });
    
    0 讨论(0)
  • 2021-02-13 16:02

    Try this.

    $('.delete_row').click(function(){
        return confirm("Are you sure you want to delete?");
    })
    
    0 讨论(0)
  • 2021-02-13 16:04

    You could also call another function after confirm like this:

    <a href="to/your/path" onclick="return confirm('Are you sure you want to delete?') && yourOtherFunction();">Delete</a>
    
    0 讨论(0)
提交回复
热议问题