首页 > 解决方案 > 我想为 utils 对话框中的按钮添加 id

问题描述

在这里,我有我的Add to library按钮。我怎样才能添加id到它?

 Utils.dialog({
                            message: save_graph_canvassheet_html,
                            title: 'Add graph to canvas library',
                            buttons: {

                                'Add to library': function () {

                                    var form = $(this).closest('.content');

                                    var title = form.find('input[name="title"]').val()
                                    var date_option = form.find('input[name="date_option"]:checked').val()

                                    if (!title) {
                                        alert($.i18n._('Please enter a title'));
                                        return false;
                                    }

                                    Utils.status({
                                        id: 'add_canvas_sheet',
                                        text: 'Adding element to library'
                                    })
                                    graph_params.class_str = instrument_class_name;
                                    delete graph_params.graph_height;
                                    delete graph_params.graph_width;
                                    delete graph_params._;

                                    $.ajax({
                                        url: '/ajax/CanvasSheet/add_element',
                                        type: 'POST',
                                        async: false,
                                        data: {
                                            title: title,
                                            params: graph_params,
                                            type: 'graph',
                                            date_option: date_option
                                        },
                                        success: function (response) {
                                            if (response.success) {
                                                $('#canvassheets_dialog').trigger('refresh_elements');
                                            }

                                            Utils.status({
                                                id: 'add_canvas_sheet'
                                            })
                                        }
                                    })
                                }
                            },
                            modal: false
                        }) 

标签: jqueryjquery-ui

解决方案


Based on LintonB's answer of this thread:

jQuery Ui Dialog Buttons, How to add class?

I guess you can do something like this:

Utils.dialog({
    message: save_graph_canvassheet_html,
    title: 'Add graph to canvas library',
    buttons: {

        'Add to library': {
            click: function () {

            var form = $(this).closest('.content');

            var title = form.find('input[name="title"]').val()
            var date_option = form.find('input[name="date_option"]:checked').val()

            if (!title) {
                alert($.i18n._('Please enter a title'));
                return false;
            }
            },
            text: 'Add to library',
            id: 'buttonID'
         }

推荐阅读