[英]How do I open a jQuery dialog and auto-set its title to the attribute in the HTML tag?
I have a div that I'm setting a title
attribute on: 我有一个div,我要在其上设置title
属性:
<div id="test" title="Test Dialog">Some test</div>
Then I open a dialog with it: 然后打开一个对话框:
$('#test').dialog({
title: $(this).attr('title')
});
The first time this dialog opens, the title is set successfully. 第一次打开此对话框时,标题设置成功。 However, if I close the dialog and re-open it, the title will be blank. 但是,如果我关闭对话框并重新打开它,标题将为空白。 This is because, the first time jQuery opens the dialog, it copies the element and removes the title
tag. 这是因为jQuery第一次打开对话框时,它会复制元素并删除title
标签。 Is there a way to get the behavior I want, where it reads the title from the title
attribute every time? 有没有一种方法可以得到我想要的行为,它每次都会从title
属性读取标题?
I'd do this in the open
event, like so: 我会在open
中这样做,就像这样:
$("#test").dialog({
open: function(event, ui) {
$(this).dialog( "option", "title", $(this).attr('title') );
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.