【问题标题】:File won't open in Chrome or Firefox, file name in URL changes to "0"文件无法在 Chrome 或 Firefox 中打开,URL 中的文件名更改为“0”
【发布时间】:2018-05-04 02:13:14
【问题描述】:

我尝试在 Google 和此处搜索“浏览器中的文件名更改为 0”,但没有找到。这是一个突然停止打开的简单文件。我什至无法让检查员解决它。撤消/重做历史丢失,所以这无济于事。我猜这是一个简单的错误,但我以前从未见过。

<!doctype html>
  <html lang="en">
  <head>
    <title>JS Animated Navigation Test</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <script>
        <!--
        var location = 0; 
        var bar = document.getElementById("bar1");

        function myMove()
        {
        // if (id != 0) clearInterval(id);
        location = -144; 
        // if (location != -144) return; // don't execute onmouseover while previous onmouseover is still running. 
        id = setInterval(move, 1);
        }  

        function move() 
        {
            location++; 
            bar.style.left = location + 'px'; 
            if (location == 300)
            {
                clearInterval(id);    
                id = setInterval(moveback, 1); 
            }  
        }

        function moveback()
        {
            location--; 
            bar.style.left = location + 'px';    
            if (location == -144)  
            {
                clearInterval(id);    
                // id = setInterval(move, 1); 
            }  
        }

    -->
    </script>
    <style>
    #container
    {
        width: 600px;
        height: 100px;
        position: relative;
        background: white;
    }
    #bar1
    {
        width: 150px;
        height: 30px;   
        position: absolute;
        left: -144px; 
        background-color: white;
    }
    </style>
</head>

<body>

<p>
<button onclick="myMove()">Click Me</button>
</p>

<div id ="container">
<div id ="animate"><img src="imageGalleryBar.png" alt="Image Gallery" width="150" height="30" id="bar1" onmouseover="myMove()" /></div>
</div>

</body>
</html>

谢谢

【问题讨论】:

  • 标记。在 HTML 的语法中,script 标签之间有一些对应的特殊大小写。
  • 好的,但他们仍然不应该使用它们,据说是为了支持旧版
  • 我真的很想看到对 SO 进行的更改,该更改需要通过文档支持否决票,即问题是重复的或不允许的。这是/现在是一个合理的问题,并且(据怀疑)是一个简单的错误。

标签: javascript html css


【解决方案1】:

你不能使用变量名location,因为它是一个保留字;您实际上正在做的是将window.location 变量设置为0

重命名它,或将其放入命名空间或对象中。

【讨论】:

  • 这是解决方案 - 这会将您发送到您的问题中描述的空白页面“0”
  • @Lawrence 不幸的是,“位置”没有作为 Notepad++ 中的保留作品出现,我完全错过了它。 非常感谢。
猜你喜欢
  • 2013-01-05
  • 2011-12-24
  • 2016-04-17
  • 1970-01-01
  • 2012-12-24
  • 2020-07-11
  • 2012-12-19
  • 2017-02-01
  • 1970-01-01
相关资源
最近更新 更多