【问题标题】:How to pass a parameter to Toaster's onClick event?如何将参数传递给 Toaster 的 onClick 事件?
【发布时间】:2018-06-27 08:26:59
【问题描述】:

我处于以下情况:我必须在 Toastr 通知单击时打开一个页面。 考虑当通知从 SignalR 到达时,弹出窗口显示在真实场景中。在我创建的道场中,它更简单,因为我有一个名为 test 的对象

你可以到达道场here

代码如下:

$(function () {

var test ={"Message" : "ciao"};

toastr.options.onclick = function(e) {alert(test.Message); }

$('#error').click(function () {
    // make it not dissappear
    toastr.error("Noooo oo oo ooooo!!!", "Title", {
        "timeOut": "0",
        "extendedTImeout": "0"
    });
});
$('#info').click(function () {
    // title is optional
    toastr.info("Info Message", "Title");
});
$('#warning').click(function () {
    toastr.warning("Warning");
});
$('#success').click(function () {
    toastr.success("YYEESSSSSSS");
});

});

我希望将测试对象作为参数传递,而不是作为全局参数传递

【问题讨论】:

  • 从哪里传递参数?你想让$('#success').clicktoastr.options.onclick 上发送参数吗?
  • 我想在用户点击通知弹出时传递一个参数,在这个演示中可以从点击事件中传递它

标签: javascript toastr


【解决方案1】:

希望现在还不算晚 - 但在类似情况下,这对我有帮助:

    toastr.options.onclick = function(e) {alert(this.data.Message); }

        $('#error').click(function () {
            // make it not dissappear
            toastr.error("Noooo oo oo ooooo!!!", "Title", {
                "timeOut": "0",
                "extendedTImeout": "0", 
                "data": {"Message": "ciao error"}
            });
        });
        $('#info').click(function () {
            // title is optional
            toastr.info("Info Message", "Title", {
                   "data": {"Message": "ciao info"}
            });
        });
        $('#warning').click(function () {
            toastr.warning("Warning");
        });
        $('#success').click(function () {
            toastr.success("YYEESSSSSSS");
        });
    });

http://jsfiddle.net/pyob98fj/

【讨论】:

  • 非常感谢,非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多