开发者

jQuery dialog button how to set the click event?

Ok i got this code:

    $(document).ready(
    function() {
        $(".dialogDiv").dialog({
            autoOpen: false,
            modal: true,
            position: [50, 50],
            buttons: {
                "Print page": function() {
                    alert("Print");
                },
                "Cancel": function() {
                    $(this).dialog("close");
                }
            }
        }
        );
    $('.ui-dialog-buttonpane button:contains("Print page")').attr("id", "dialog_print-button");
    $(".dialogDiv").parent().appendTo($('form'));
    }

How do I assign or set a new function to the click event?

$("#dialog_开发者_如何学运维print-button"). ???

Edit, This works:

$("#dialog_print-button").unbind("click").click(
function () {
   alert("new function that overide the old ones")
}
)

Tried to find how to do in the jQuery documentation but I think it's hard to find around in the documentation. Especially when new to javaScript and the jQuery libary.

Edit, A fast way to get help is to go to jQuery irc channel :D


I think this would help:

$(".dialogDiv").dialog("option", "buttons", {
    "Print page": function() { /* new action */ },
    "Cancel": function() { $(this).dialog("close"); }
});

Because buttons property sets all the buttons, you have to include cancel button handler.


$("#Print page").click(function () {
   ...
});

Or maybe it should be

$("#dialog_print-button").click(function () {
   ...
});


jQuery UI dialog buttons now supports the "id" attribute natively.

    $("#dialog-form").dialog({
        autoOpen: false,
        height: "auto",
        width: 300,
        buttons:
        [
            {
                text: "Create Revision",
                id: "btnCreateRev",
                click: function () {
                    //code for creating a revision
                }
            },
            {
                text: "Cancel",
                id: "btnCancel",
                click: function () { $(this).dialog("close"); },
            }
        ]
    });


You put the code within the button section:

 ...
 buttons: {                   
         "Print page": function() {                       
          //here you execute the code or call external functions as needed 
          }

Once you click the button on the Dialog, that code is automatically invoked. Therefore you insert there directly the code that implements your logic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜