简体   繁体   English

为什么不加载我的JS文件?

[英]Why won't my JS file load?

using this code: 使用此代码:

<script src="<?php bloginfo('template_url'); ?>/scripts/hovermenus.js" type="text/javascript"></script>

to load this script 加载此脚本

firebug is not showing this script as loaded, however, these scripts: firebug并未显示此脚本已加载,但是这些脚本如下:

<script src="<?php bloginfo('template_url'); ?>/scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="<?php bloginfo('template_url'); ?>/scripts/salf_ui.js" type="text/javascript"></script>
    <script src="<?php bloginfo('template_url'); ?>/scripts/date.js" type="text/javascript"></script>
    <script src="<?php bloginfo('template_url'); ?>/scripts/datePicker.js" type="text/javascript"></script>

all load perfectly well. 所有负载都很好。 I have double, triple and quadruple checked the file is in the right directory. 我已经检查过两次,三次和四次文件是否在正确的目录中。

Looks like the problem is with your file 看来问题出在您的档案上

Make sure the file .../scripts/hovermenus.js exists. 确保文件.../scripts/hovermenus.js存在。 Navigate there and copy paste the file name from there. 导航到那里,然后从那里复制粘贴文件名。

Could the script be in another directory? 脚本可以在另一个目录中吗? could it be hoverMenus.js or hover.menus.js .... etc. 可能是hoverMenus.jshover.menus.js ....等

If none of this works, try copying and renaming the file. 如果这些都不起作用,请尝试复制并重命名文件。 See if you can load the renamed version. 查看是否可以加载重命名的版本。 If you can't, it's something in the file. 如果不能,那就是文件中的内容。

Unrelated: You should declare your variables with var so you don't create a bunch of global variables attached to window . 不相关:您应该使用var声明变量,这样就不会创建附加到window的全局变量。

I had the similar problem: same file would not load on other pages(master pages) 我有类似的问题:同一文件不会在其他页面(母版页)上加载

original: 

   <script type="text/javascript" src="../../Scripts/scriptMob.js"></script>

fixed:    
   <script type="text/javascript" src="/Scripts/scriptMob.js"></script>

only removed dots and first slash 只删除点和第一个斜杠

Additionally you can check in firebug(HTML section), expand the reference line 另外,您可以签入firebug(HTML部分),展开参考线

    (+) <script src="../../Scripts/scriptMob.js" type="text/javascript"> 

to check whether browser actually reads the js file correctly. 检查浏览器是否正确读取了js文件。

the error message was saying: [SqlException]: Error converting data type nvarchar to int. 错误消息说:[SqlException]:将数据类型nvarchar转换为int时出错。

charset isnt a valid attribute for the script tag, try removing it charset不是脚本标记的有效属性,请尝试将其删除

EDIT 编辑

Actually it is valid, try removing it anyway :) 实际上它是有效的,无论如何都尝试将其删除:)

确保已关闭要加载的脚本标记上方的所有脚本标记。

Had a similar problem, shoving my head against a wall trying to figure it out. 遇到了类似的问题,将我的头推到墙上试图解决。 Turned out the js file had a syntax issue buried in it, something stupid that didn't show in my editor ... in this case it was a hanging 'var ' with nothing after it. 原来js文件中隐藏了语法问题,这在我的编辑器中没有显示出来,这很愚蠢……在这种情况下,它是一个悬挂的'var',后面没有任何内容。 As soon as I deleted that, everything was copacetic. 我一删除该文件,一切就结束了。

So my recommendation if you run into this is what I did - remove all functions and add them back one by one until you find one that kills it. 因此,如果遇到这种情况,我的建议是我所做的-删除所有功能,并将它们一个接一个地添加,直到找到一个将其杀死的功能。

遇到类似的问题,无法加载脚本/js/search_ads.js这是我的adblock扩展中的问题重命名为search.js之后,问题消失了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM