Javascript在Firefox中工作,但现在来自Web服务器时在Chrome中工作

Javascript works in Firefox but now in Chrome when coming from web server

本文关键字:工作 Web 服务器 Chrome Firefox Javascript      更新时间:2023-09-26

我正在测试一个网页,当单击不同的容器时,该网页会隐藏和取消隐藏div容器。我测试了这是 Chrome,它运行良好,但是在我将其放在我的网络服务器上后,我遇到了未定义的错误。当我从Web服务器在Firefox中测试它时,它工作正常。它在Lubuntu中的Chromium上运行良好,但是Windows中的Chrome给了我一个错误。

<!DOCTYPE html PUBLIC 
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Chrome test</title>
        <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
        <script type="text/javascript">
            function hideDiv(nameId) {
                var grouping = document.getElementById(nameId); 
                if(grouping.style.display == 'none') {
                    grouping.style.display = '';
                } else {
                    grouping.style.display = 'none';
                }
            }
        </script>
    </head>
    <body>
        <div id="group">
            <div id="header" onclick="hideDiv('failingtoclose');">
                <span>Testing</span>
            </div>
            <div id="failingtoclose">
                <span>More testing</span>
            </div>
        </div>
    </body>
</html>

开发人员的工具给我的警告:
'window.webkitStorageInfo' 已被弃用。请使用"navigator.webkitTemporaryStorage"或"navigator.webkitPersistentStorage"。

和错误:
未捕获的类型错误:无法读取未定义的属性"显示"(第 9 行)

Web 服务器在 Ubuntu 上运行 apache 2.2.22。

它在Windows(版本30.0.1599.69 M)上的Chrome中运行良好,我怀疑它与服务器有关,因为没有交互正在进行,至少在您提供的代码中。将文档类型更改为标准模式(<!DOCTYPE html>)可能会有所帮助,因为某些浏览器会感到困惑(尽管我怀疑chrome确实如此)。