繁体   English   中英

noty,点击按钮调用函数

[英]noty, call a function on button click

这是一个原型函数,用于使用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;
}

我用语法调用此函数,

confirmation("Are you sure want to delete this item?", "delete("+id+")");

因此,在单击“是”按钮时,必须调用另一个函数delete(id) 但是,为什么呢?

我检查了警报alert(call_func) 我警告为delete(10) ,其中实例的ID为10。

好吧,这里您没有调用该函数

call_func;  

你只是在引用它

在这里,您只是构建一个字符串

"delete("+id+")")

它不是对函数调用的引用。


您需要做的是传递一个实际函数并执行该函数。

confirmation("Are you sure want to delete this item?", function(){ delete(id); });

call_func();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM