尝试使用toastr时出现“toastr不是函数错误”的错误提示

6

我想使用toastr来通知用户。我已经按照这个指南进行设置。但是我收到了错误信息:Uncaught TypeError: toastr is not a function。我查看了网络选项卡,文件正确加载。为了确保,我尝试使用cdn,但没有成功。以下是我的使用方式:

    toastr('Are you the 6 fingered man?');

就像演示中的一样。关于我做错了什么,您有什么建议吗?

你是否在这行代码之前引入了toastr脚本? - sabithpocker
是的,已经解决了。必须像这样声明toastrCommand: toastr["success"]("test message", "test") - AllramEst
所以您可能想要发布一个自己的回答,详细描述问题所在以及需要采取哪些措施来解决它,或者删除您自己的帖子。 - connexo
3个回答

8
根据您提供的文档,应该这样使用:
toastr.info('Are you the 6 fingered man?')

你忘记调用函数info()。


我试了你的代码,当然它运行成功了,谢谢。对于浪费你的时间,我很抱歉。 - AllramEst

6
您需要按照以下方式使用toastr函数。
请参见文档
// Display a warning toast, with no title
toastr.warning('My name is Inigo Montoya. You killed my father, prepare to die!')

// Display a success toast, with a title
toastr.success('Have fun storming the castle!', 'Miracle Max Says')

// Display an error toast, with a title
toastr.error('I do not think that word means what you think it means.', 'Inconceivable!')

// Immediately remove current toasts without using animation
toastr.remove()

// Remove current toasts using animation
toastr.clear()

// Override global options
toastr.success('We do have the Kapua suite available.', 'Turtle Bay Resort', {timeOut: 5000})

意识到它知道了。 - AllramEst

2
请使用 toastr 来显示信息,包括 info, warning, success 和 error 选项。
toastr.info('Are you the 6 fingered man?');

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接