【问题标题】:Getting error "toastr is not a function error" when trying to use toastr尝试使用 toastr 时出现错误“toastr 不是函数错误”
【发布时间】:2018-06-01 17:16:29
【问题描述】:

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

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

与演示一样。关于我做错了什么有什么建议吗?

【问题讨论】:

  • 这一行之前是否包含toastr脚本?
  • 是的。并解决了它。必须像这样Command: toastr["success"]("test message", "test") 声明toastr
  • 因此,您可能希望发布自己问题的答案,详细描述问题所在以及需要采取哪些措施来解决问题,或者删除您自己的帖子。

标签: javascript jquery toastr


【解决方案1】:

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

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

你忘了调用函数 info()。

【讨论】:

  • 试过你的代码,当然它工作了,谢谢。很抱歉浪费了您的时间。
【解决方案2】:

您需要按照下面的方式使用 toastr 函数。

documentation

// 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})

【讨论】:

  • 意识到它知道。
【解决方案3】:

请使用带有信息、警告、成功、错误或选项的 toastr。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-06
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 2021-01-30
    • 2023-04-02
    • 1970-01-01
    • 2023-04-10
    相关资源
    最近更新 更多