为什么获胜't这个javascript在一个网站上有效,但在另一个网站却有效

Why won't this javascript work on one site, but does on another?

本文关键字:网站 有效 一个 另一个 获胜 javascript 这个 为什么      更新时间:2023-09-26

所以我在两个不同的地方建立了一个网站,其中一个网站运行良好,另一个网站的代码无法运行。即使我在浏览器中打开它,它也无法工作。

当有人将鼠标悬停在图像上时,脚本应该将图像的不透明度从0.6->1更改。现在它在原来的位置工作,在新的位置它不工作,当我直接打开它时,它在我的电脑上也不工作。

代码时间:

这是images.js

$(function()
{
    $("#footer img").hover
        (
        function()
        {
            $(this).stop().animate({"opacity": "1"}, "slow");
        },
        function()
        {
            $(this).stop().animate({"opacity": "0.6"}, "slow");
        }
    );
});

这是页面上调用上述文件的代码:

<script type="text/JavaScript" src="/_resources/javascript/images.js"></script>

最后是需要受代码影响的图像所在的页脚:

<div id="footer">
<a href="completed-roofing-works/test.html"><img src="_resources/images/footer-3.jpg" alt="image 2" /></a>
<a href="completed-roofing-works/completed-roofing-works-two.html"><img src="_resources/images/footer-6.jpg" alt="image 1" /></a>
<a href="completed-roofing-works/test.html"><img src="_resources/images/footer-1.jpg" alt="image 3" /></a>
<a href="testimonials/test.html"><img src="_resources/images/footer-4.jpg" alt="Roofers Kent" /></a><a href="testimonials/test.html"><img src="_resources/images/footer-2.jpg" alt="image 4" /></a>
<a href="testimonials/test.html"><img src="_resources/images/footer-5.jpg" alt="image 5" /></a>
</div></div>

现在坐在这里,我唯一能想到的就是没有安装Javascript,你认为可能是这样吗?

谢谢。

:编辑:

看完之后,我注意到可能是这个脚本与它发生了冲突:

<script language="javascript"> 
 var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows'sce|palm/i.test(navigator.userAgent.toLowerCase()));
          if (mobile) {
               window.location.replace("mobile/choose.html");
          }

    </script>

它直接位于调用images.js文件的代码之后

解决了谢谢:

对于将来有类似问题的人来说:删除目录名之前的/,这似乎非常不喜欢。

您拥有的代码是jQuery。jQuery是一个需要显式包含的库。

这与VanillaJS形成了鲜明对比,VanillaJS非常好,多年来浏览器一直将其作为标准提供,不需要任何激活或包含。

然而,在这种情况下,即使是VanillaJS也显得有些过头了。

CSS:

#footer img {
    opacity: 0.6;
    transition: all 0.8s ease;
}
#footer img:hover {
    opacity: 1;
}