[英]noty, call a function on button click
This is a prototype function I use for displaying confirmation with buttons using noty . 这是一个原型函数,用于使用noty显示带有按钮的确认。
function confirmation(message, call_func)
{
var m=noty(
{
text: message,
modal: true,
layout : 'center',
theme: 'notifications',
buttons: [
{
addClass: 'general-button red', text: 'Yes', onClick: function($noty)
{
call_func;
$noty.close();
}
},
{
addClass: 'general-button', text: 'No', onClick: function($noty)
{
$noty.close();
}
}]
});
return m;
}
I am calling this function with the syntax, 我用语法调用此函数,
confirmation("Are you sure want to delete this item?", "delete("+id+")");
So on clicking the Yes button, another function delete(id)
have to be called. 因此,在单击“是”按钮时,必须调用另一个函数delete(id)
。 But it does not, why? 但是,为什么呢?
I checked with alert, alert(call_func)
. 我检查了警报alert(call_func)
。 I alerts as delete(10) where 10 is ID at the instance. 我警告为delete(10) ,其中实例的ID为10。
Well here you are not calling the function 好吧,这里您没有调用该函数
call_func;
you are just referencing it 你只是在引用它
And here you are just building a string 在这里,您只是构建一个字符串
"delete("+id+")")
it is not a reference to a function call. 它不是对函数调用的引用。
What you need to do is pass in an actual function and execute the function. 您需要做的是传递一个实际函数并执行该函数。
confirmation("Are you sure want to delete this item?", function(){ delete(id); });
and 和
call_func();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.