You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaScript报错TypeError: showToastrMessage.init is not a function 求助

Fixing "showToastrMessage.init is not a function" Error

Hey there! Let's break down exactly why you're hitting this error and how to fix it.

The Root of the Problem

Looking at your code, you've defined showToastrMessage as a plain function:

var showToastrMessage = function(){ 
  toastr.success('sdfsdfd'); 
}

But then you're trying to call an .init() method on it like it's an object or class with built-in methods:

showToastrMessage.init() // This fails because plain functions don't have an `init` property

That's why the console throws TypeError: showToastrMessage.init is not a function—the function you created doesn't have an init method attached to it.

Two Simple Fixes

Fix 1: Just Call the Function Directly

If your goal is simply to run the toastr message when the document is ready, you don't need .init() at all. Just invoke the function directly:

var showToastrMessage = function(){ 
  toastr.success('sdfsdfd'); 
} 

jQuery(document).ready(function() { 
  showToastrMessage(); // No .init() needed—just call the function normally
});

Fix 2: Restructure as an Object with an init Method

If you want to organize your code using an object-based pattern (common for grouping related functionality), redefine showToastrMessage as an object that contains the init method:

var showToastrMessage = {
  init: function() {
    toastr.success('sdfsdfd');
  }
};

jQuery(document).ready(function() { 
  showToastrMessage.init(); // Now this works—we're calling the method on the object
});

Quick Extra Check

Make sure the toastr library is properly loaded on your page before your code runs. If toastr isn't loaded, even a correctly called toastr.success() will throw an error!

内容的提问来源于stack exchange,提问作者Adnan Rafique

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:18:42