我的问题对你来说可能很简单,但我花了更多的时间来寻找解决方案。好吧,我的问题是:我在我的网络应用程序中使用 jquery.ui 对话框。我制作了一个对话框,它必须在关闭对话框之前按名称 before_close
调用一个函数。我的对话框看起来像这样:
jQuery('#edit_user_form').dialog({
'autoOpen':false,
'title':'Изменить',
'modal':true,
'position':['center',60],
'width':600,
'resizable':false,
'close':before_close
});
它是 before_close 函数:
function before_close (text) {
$('#edit_user_form .update-dialog-content').html(text);
}
如您所见,before_close 有一个参数。我可以在创建对话框时绑定(bind)参数
jQuery('#edit_user_form').dialog({
'autoOpen':false,
'title':'Изменить',
'modal':true,
'position':['center',60],
'width':600,
'resizable':false,
'close': before_close(anytext) // or before_close.apply(anytext)
/* above code called before_close when the dialog was created */
});
如何在关闭对话框时添加调用 before_close
的参数?提前致谢!
最佳答案
创建一个匿名函数
并从中调用before_close(anytext)
jQuery('#edit_user_form').dialog({
'autoOpen':false,
'title':'Изменить',
'modal':true,
'position':['center',60],
'width':600,
'resizable':false,
'close': function(){before_close(anytext);} // or before_close.apply(anytext)
/* above code called before_close when the dialog was created */
});
关于javascript - 向函数添加参数而不在 javascript 上调用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25659431/