$ is undefined error in jquery

前端 未结 6 1294
眼角桃花
眼角桃花 2020-12-11 02:56

I am getting this error while using twitter bootstrap. I didn\'t get this error when using it in html. I converted it into a wordpress theme, and now i am getting this error

6条回答
  •  余生分开走
    2020-12-11 03:38

    I had this exact same problem. I was originally, basically, front loading all my javascript files, including bootstrap, into one mega-bundle as follows:

        bundles.Add(New ScriptBundle("~/bundles/jquery-etc").Include(
                    "~/Scripts/jquery-{version}.js",
                    "~/Scripts/jquery-ui-{version}.js",
                    "~/Scripts/bootstrap.js",
                    "~/Scripts/respond.js",
                    [other js files here]))
    

    I was thinking that bootstrap was loading AFTER jquery so it should be ok. Nope. So I put bootstrap into a separate bundle as follows:

             bundles.Add(New ScriptBundle("~/bundles/jquery-etc").Include(
                    "~/Scripts/jquery-{version}.js",
                    "~/Scripts/jquery-ui-{version}.js",
                    [other js files here]))
    
    
              bundles.Add(New ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Scripts/bootstrap.js",
                  "~/Scripts/respond.js"))
    

    This caused bootstrap to load property AFTER Jquery. Probably djb's solution would have done the job too. But this worked for me.

提交回复
热议问题