javascript - 向函数添加参数而不在 javascript 上调用它

标签 javascript jquery

我的问题对你来说可能很简单,但我花了更多的时间来寻找解决方案。好吧,我的问题是:我在我的网络应用程序中使用 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/

相关文章:

Javascript RegExp 将字符串中的所有数字减一

javascript - 实现垂直选项卡时出现下拉菜单问题(Twitter Bootstrap)

asp.net - 当传出内容长度超过 3508 字节时,XMLHttpRequest 失败。为什么?

javascript - angular.controller 是否总是采用匿名函数

javascript - AmCharts - 带有自定义 map 的 AmMap 颠倒显示

javascript - 在可编辑按钮中显示保存底部编辑文本

javascript - 如果背景图像 url = 那么

javascript - bootstrap.css 和 web.css 文件的区别?

javascript - 使用 jQuery 将参数从 MVC View 传递到操作

javascript - 设置第二条验证消息