Jquery - waiting for user input

后端 未结 1 511
悲&欢浪女
悲&欢浪女 2021-01-19 04:49

im trying to make a popup that comes up to confirm a users action (deleting a row in a table, for example..). aiming at making the popup entirely HTML and Javascript. What i

相关标签:
1条回答
  • 2021-01-19 05:21

    you can implement something like this

    makePopup("Are you sure?", function {
      //bla bla 
    });
    

    which will call your callback only if user sure, after he clicks a button or whatever. Smth like:

    function makePopup(msg, callback) {
         $("#sureformmsg").html(msg);
         $("#sureform").show().submit(function() { if (..check..) callback(); });
    }
    

    Your example:

    $(document).ready(function(){
        $('a').click(function(){
            makePopup("Wana go to google?",function(){
                window.location.replace("http://www.google.com");
            });
        });
    });
    
    function makePopup(msg,callback){
        $('body').append("<div class='popup'><p id='themsg'>"+msg+"</p></div>");
        $('#themsg').onclick(callback);
    }
    
    0 讨论(0)
提交回复
热议问题