如何在jquery中结束链,然后在链函数中执行函数
我知道这在语言上是一个奇怪的问题,所以基本上我是这样说的。我有这个:如何在jquery中结束链,然后在链函数中执行函数,jquery,dialog,position,modal-dialog,Jquery,Dialog,Position,Modal Dialog,我知道这在语言上是一个奇怪的问题,所以基本上我是这样说的。我有这个: $("#dialog-areyousuremodal").dialog({ resizable: false, height: 120, modal: true, buttons: { "Yes": function() { $(this).dialog("close"); // more stuff coming soon
$("#dialog-areyousuremodal").dialog({
resizable: false,
height: 120,
modal: true,
buttons: {
"Yes": function() {
$(this).dialog("close");
// more stuff coming soon
},
"No": function() {
$(this).dialog("close");
}
}
}).end().centerFixed();
<div class="hidden" id="dialog-areyousuremodal" title="Delete Confirmation">
<p>Are you sure you want to delete this row?</p>
</div>
我的目标是替换.end().centerFixed();使用just.centerFixed();。如您所见,我尝试将.end()放在自定义函数中,但这不起作用。我试图避免将.end()放在对话框的末尾,或将.centerFixed()放在新行
对这件事有什么想法吗?恐怕你不能这么做,当调用
centerFixed()
时,它没有在最后调用的函数链的概念。它所知道的就是这个
,它是从前面的chain方法中调用的函数返回的任何对象
由于在调用dialog()
结束时将其链接,因此在centerFixed
内部,变量this
将是调用dialog()
的结果(我认为是UI dialog对象)
如果你想确保你的代码只在对话框创建时运行,最好的方法是使用插件的我挠头了,想不出你为什么要这么做。你能解释一下为什么不能使用
end()
,可能有一个更简单的解决方案吗?如果你问我为什么需要在运行我的函数之前结束链:原因是在我更改css之前需要创建jqueryui的对话框窗口。如果你问我为什么需要它工作而不必键入end()或者去一条新线,这是因为我的队友只是想让它这样工作。(我知道,这很疯狂,但嘿……我被淘汰了)
(function($){
$.fn.extend({
centerFixed: function () {
return this.each(function() {
$(this).end();
$(this).css({position:"fixed"});
$(this).css("top", (($(window).height() - $(this).outerHeight()) / 2) + "px");
$(this).css("left", (($(window).width() - $(this).outerWidth()) / 2) + "px");
});
}
});
})(jQuery);