为toastr通知调用jquery函数

时间:2014-03-14 00:54:16

标签: javascript jquery toastr

我希望在点击这些链接但没有任何反应时弹出toastr的通知

编辑:这是完整代码http://jsfiddle.net/XaVcR/的jsfiddle我不确定我是否正确包含toastr尽管          成功       的.js

toastr.options.closeButton = true;
toastr.options.positionClass = "toast-bottom-left";

$(document).ready(function() {
    $('#success').click(notification('success', 'this was a success!'));
});

function notification( type, message ) {
if( type == 'success' ) {
    toastr.success(message,'<i>Success</i>');
} else if( type == 'error' ) {
    toastr.error(message,'Error');
} else if( type == 'warning' ) {
    toastr.warning(message,'Warning');
} else {
    toastr.info(message,'Information');
}   
}

1 个答案:

答案 0 :(得分:2)

从问题:

    $('#success').click(notification('success', 'this was a success!'));

这应该是:

$('#success').click(function() {
    notification('success', 'this was a success!');
});

你的JSFiddle有:

$('#success').click(function() {
    notification('success', 'this was a success!'));
});

,中间行末尾的))是语法错误。