Pass a variable to JQuery UI dialog

前端 未结 4 781
甜味超标
甜味超标 2020-12-09 08:12

I am deleting a record using PHP. I want to use a JQuery UI dialog to confirm the action, but I dont know how to pass a variable (my RecordID) to the redirect URL function,

4条回答
  •  眼角桃花
    2020-12-09 08:51

    Deleting actions probably shouldn't be done using a GET, but if you wanted to do it that way I would recommend using the $.data in jQuery so each link had a data-record-id attribute. Then on click of one of the links, it pops up the dialog and when confirmed it adds that to the URL, and redirects. Example:

    $(function(){
        $(".deleteLink").click(function(){
           var id = $(this).data("record-id");
           var myHref = $(this).attr('href');
            $("#confirmDialog").dialog({
                buttons:{
                "Yes": function()
                    {
                        window.location.href = myHref + id;
                    }
                }
            });
        });
    

    });

    Delete
    ...
    

    Are you sure?

提交回复
热议问题