更新时间:2023-02-11 14:39:18
你实际上需要一种不同的方法,直观的,像这样:
You actually need a different approach here, a non-intuitive one, like this:
jQuery(function($) {
$('.helpButton').each(function() {
$.data(this, 'dialog',
$(this).next('.helpDialog').dialog({
autoOpen: false,
modal: true,
title: 'Info',
width: 600,
height: 400,
position: [200,0],
draggable: false
})
);
}).click(function() {
$.data(this, 'dialog').dialog('open');
return false;
});
});
为什么要这样做?因为 .dialog()
将包含在对话框元素中的内容移动到结束< body>
,所以 .next()
将不会再找到...通过使用 jQuery.data()
我们正在保留对我们要打开的对话框的引用。
Why must you do this? because .dialog()
moves the content it wraps in dialog elements to the end of the <body>
, so .next()
will no longer find it...by using jQuery.data()
we're maintaining a reference to the dialog we want to open.