簡體   English   中英

如何打開jQuery對話框並將其標題自動設置為HTML標記中的屬性?

[英]How do I open a jQuery dialog and auto-set its title to the attribute in the HTML tag?

我有一個div,我要在其上設置title屬性:

<div id="test" title="Test Dialog">Some test</div>

然后打開一個對話框:

$('#test').dialog({
    title: $(this).attr('title')
});

第一次打開此對話框時,標題設置成功。 但是,如果我關閉對話框並重新打開它,標題將為空白。 這是因為jQuery第一次打開對話框時,它會復制元素並刪除title標簽。 有沒有一種方法可以得到我想要的行為,它每次都會從title屬性讀取標題?

我會在open中這樣做,就像這樣:

$("#test").dialog({
   open: function(event, ui) { 
      $(this).dialog( "option", "title", $(this).attr('title') );
   }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM