javascript - Setting a jQuery dialog button callback - Stack Overflow

Hey coders, i would like to initialize a dialog box with a callback function for say a 'save'

Hey coders, i would like to initialize a dialog box with a callback function for say a 'save' button but i want the callback to reside as a standalone function rather than defined inline using function(){....} the code snippet below highlights what I want to do.

$( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 300,
        width: 350,
        modal: true,
        buttons: {
            "Save": saveAction() 
...
function saveAction()  
{  
}  

what is the proper syntax for the "Save": saveAction() line cause it is doesn't seem to work?

thanks

Hey coders, i would like to initialize a dialog box with a callback function for say a 'save' button but i want the callback to reside as a standalone function rather than defined inline using function(){....} the code snippet below highlights what I want to do.

$( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 300,
        width: 350,
        modal: true,
        buttons: {
            "Save": saveAction() 
...
function saveAction()  
{  
}  

what is the proper syntax for the "Save": saveAction() line cause it is doesn't seem to work?

thanks

Share Improve this question asked Jan 29, 2011 at 18:07 djeeteedjeetee 1,8377 gold badges26 silver badges38 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

The parens after saveAction makes the function execute. Use this instead:

        "Save": saveAction

saveAction must have parameters defined in the signature: i.e. saveAction(a,b,c), then when setting the callback do this:

"Save": saveAction({a = "val", b = "val", c = "val"})

If you have to pass in parameters, you must wrap your function call in an anonymous function definition, like this:

"Save": function() { saveAction({a = "val", b = "val", c = "val"}) }

This effectively defines a new anonymous function that takes no parameters, and which when executed will call your own function with your desired paramters.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745247391a4618473.html

相关推荐

  • javascript - Setting a jQuery dialog button callback - Stack Overflow

    Hey coders, i would like to initialize a dialog box with a callback function for say a 'save'

    6小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信