【问题标题】:javascript module not being found找不到javascript模块
【发布时间】:2014-05-15 19:47:34
【问题描述】:

我有一堆网页,其中我有一个相同的结构:

<html>
<head>
    <script src="sorttable.js"></script>
    <noscript>
        <meta http-equiv="refresh" content="60">
    </noscript>
    <script type="text/javascript">
        <!--
        var sURL = unescape(window.location.pathname);
        function doLoad()
        { 
            setTimeout( "parent.frames['header_frame'].document.submitform.submit()", 60*1000 ); 
        }
        function refresh()
        { 
            window.location.href = sURL; 
        }
        //-->
    </script>
    <script type="text/javascript">
        <!--
        function refresh()
        { 
            window.location.replace( sURL ); 
        }
        //-->
    </script>
    <script type="text/javascript">
        <!--
        function refresh()
        { 
            window.location.reload( true ); 
        }
        //-->
    </script>
</head>
<body>
    .
    .
    .
    <script type="text/javascript">
        window.onload = function() { sorttable.innerSortFunction.apply(document.getElementById("OpenFace-2"), []); doLoad(); }
    </script>
</body>
</html>

这在每个页面都可以完美运行,除了一个页面,当 onload 函数运行时,它找不到可排序的代码(从顶部的 sorttable.js 加载)。所有这些页面都是同一个应用程序的一部分,并且都与 js 文件位于同一个目录中。在加载该页面之前,我在 apache 日志或 js 控制台中没有收到任何错误,当我得到:

sorttable.innerSortFunction is undefined

我看不出是什么让这一页与众不同。谁能看到这里出了什么问题,或者给我一些关于如何进一步调试的指示?

我粘贴的代码来自它不起作用的页面的源代码,但它与它起作用的页面相同。

【问题讨论】:

  • 不要在字符串中使用setTimeoutsetInterval,因为它就像邪恶的eval!改用函数:setTimeout(parent.frames['header_frame'].document.submitform.submit, 60e3)
  • @Luxelin - 是的,这就是我们正在使用的排序表
  • 所有页面都在同一个路径中吗?控制台浏览器中有任何消息吗?如果此页面在其他路径,则需要将
  • @Oriol - 但这不是问题 - doLoad() 函数有效 - 抛出错误的是 window.onload()。但为了确保我做出了您建议的更改 - 它并没有解决我的问题,并且导致我的页面不断刷新,而不是每分钟刷新一次。

标签: javascript html sorttable.js


【解决方案1】:

在该页面上,您尝试排序的 ID 为 OpenPhace-2 的表似乎不需要类:sortable

sorttable 对象的函数innerSortFunction 仅在存在任何具有sortable 类的表时才会出现。

【讨论】:

  • 你的意思是./?在任何情况下,我都尝试了 / 和 ./,但都没有解决问题。
  • 您能否提供您使用的库的确切源代码的链接?
  • 请检查该页面上表的类名
  • 类名正确。事实上,我发布的代码来自一个通用函数(这是 PHP 生成的),该函数在我的所有页面中都使用,并且它适用于除此之外的每个页面。
  • 这确实是个问题。在那一页上没有带有可排序类的表。非常感谢。
猜你喜欢
  • 2016-08-30
  • 2022-12-15
  • 2022-01-20
  • 1970-01-01
  • 2018-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-23
相关资源
最近更新 更多