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

新手上路,请多包涵

我想使用 toastr 来通知用户。我已按照 指南进行设置。但我收到错误消息: Uncaught TypeError: toastr is not a function 。我查看了网络选项卡,文件正在正确加载。尝试使用 cdn 来确定。但没有运气。这就是我尝试使用它的方式:

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

就像在演示中一样。关于我做错了什么的任何建议?

原文由 AllramEst 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 758
2 个回答

根据您链接的文档,应该这样使用:

 toastr.info('Are you the 6 fingered man?')

您忘记调用函数 info()。

原文由 tobiso 发布,翻译遵循 CC BY-SA 3.0 许可协议

您需要按照以下方式使用 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})

原文由 Shalitha Suranga 发布,翻译遵循 CC BY-SA 3.0 许可协议

推荐问题