2013-03-06 35 views
0

我需要将jQuery对话框的标题发送到服务器,是否有可能检索它,而无需遍历DOM并找到?如何获取包含Jquery对话框的标题?

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

$(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 }); 
          } 
         }); 
        } 
       } 
      }); 
     } 

回答

5

你可以通过调用

var title = $(".selector").dialog("option", "title"); 

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

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

$("div#dialog").data("uiDialog").options.title 

我不使用第二reccomend因为它可能依赖于jQuery版本和将来的更改,它只是illustra它是如何工作的。

当然,调整自己的选择,选择合适的对话框中,如果你调用从对话框按钮此阿贾克斯,那么它应该是$(this)