【问题标题】:noty, call a function on button click注意,单击按钮时调用函数
【发布时间】:2014-05-15 12:18:30
【问题描述】:

这是一个原型函数,我使用 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) 发出警报,其中 10 是实例的 ID。

【问题讨论】:

  • 试试这个 eval(call_func);而不仅仅是 call_func;

标签: javascript jquery noty


【解决方案1】:

这里你没有调用函数

call_func;  

你只是在引用它

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

"delete("+id+")")

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


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

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

call_func();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 2019-10-04
    • 2020-08-29
    相关资源
    最近更新 更多