如何获取包含Jquery对话框的标题?

Xer*_*xes 0 jquery

我需要将jquery对话框的标题发送到服务器,是否可以在不遍历DOM的情况下检索它并找到?

我知道<span class="ui-dialog-title"></span>可以使用jQuery检索(),但我想知道是否有更好的方法.

 $(c[0]).html(html).dialog({
                title: "Brief Country List",
                resizable: false,
                draggable: false,
                width: 900,
                modal: true,
                autoOpen: true,
                buttons: {
                    Done: function () {
                        Neptune.BriefCountrySection.SaveCountry();
                    },
                    Export: function () {

                        $.ajax({
                            type: 'POST',
                            url: '/Briefs/ExportCsv',
                            data: /*Get the title here*/,
                            dataType: 'JSON',
                            contentType: 'application/json; charset=utf-8',
                            success: function (res) {
                                if (res.Success) {
                                    var item = ko.utils.arrayFirst(self.Countries(), function (i) {
                                        return i.ListID() == self.SelectedCountryListID();
                                    });

                                    if (item != null) {
                                        self.Countries.remove(item);
                                    }
                                }
                                else {
                                    Neptune.ShowAlert({ content: res.FriendlyErrorMessage });
                                }
                            },
                            error: function (jqXHR, status, err) {
                                Neptune.ShowAlert({ content: status });
                            }
                        });
                    }
                }
            });
        }
Run Code Online (Sandbox Code Playgroud)

Gor*_*vic 5

你可以通过电话来获得

var title = $( ".selector" ).dialog( "option", "title" );
Run Code Online (Sandbox Code Playgroud)

http://api.jqueryui.com/1.9/dialog/#option-title

这些选项包含在dom元素的数据中

$("div#dialog").data("uiDialog").options.title
Run Code Online (Sandbox Code Playgroud)

我不建议使用第二种方式,因为它可能依赖于jQuery版本并在将来进行更改,它只是说明它是如何工作的.

当然,调整选择器以选择正确的对话框,如果从对话框按钮调用此ajax,那么它应该是 $(this)