Jquery - waiting for user input

帅比萌擦擦* 提交于 2019-12-01 19:22:23

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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!