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 badges3 Answers
Reset to default 4The 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
评论列表(0条)