2013-03-06 17 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)