简体   繁体   中英

How would I add a “add” button to this code?

Sorry for my lack of knowing JS. But I have this Jquery dialog code and need to add a button that says "Add" and would call a new blank dialog? I'm a UX/UI designer and syntax messes me up, lol. Any help would be great.

    $( "#dialog-message" ).dialog({
    autoOpen: false,
    modal: true,
    buttons: {
        Ok: function() {
            $( this ).dialog( "close" );
        }
    }
});

$( "#opener" ).click(function() {
    $( "#dialog-message" ).dialog(  "option", "width", 650  );
    $( "#dialog-message" ).dialog( "open" );
    return false;
}); 

The buttons property is a javascript literal object , so you can add a button like this:

buttons: {
    Ok: function() {
        $( this ).dialog( "close" );
    },
    Add : function() {
      $('#otherDialog').dialog("open");
    }
}

As you can see, they are functions separated by comma and the name will be used as text.

Try this:

$(function() {
    $( "#opener" ).click(function() {
        $( "#dialog-modal" ).dialog({
            width: 650,
            modal: true,
            buttons: {
                Ok: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM