jQuery在任何浏览器中都不起作用(没有任何效果),但它在Codepen中工作

jQuery not working (not having any effect) in any browser, but it works in Codepen

本文关键字:Codepen 任何效 工作 浏览器 任何 不起作用 jQuery      更新时间:2023-09-26

这让我感到沮丧已经很久了。我尝试将jQuery下载为本地文件,并尝试将其链接到http。路径是正确的,实际代码中没有错误,因为它在 Codepen 中完美运行。它位于正确的位置。我尝试将其放在<head>标签中,也放在</body>标签之前,但仍然没有运气 - 没有任何反应。在这里:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/js/javascript.js"></script>  

我尝试使用的代码是:

$(document).ready(function() {
    $('.item').hover(function() {
        $(this).stop().animate({ width: '100%' }, 500);
    }, function() {
        $(this).stop().animate({ width: '96%' }, 500);
    });
});

有什么理由可以这样吗?常规的Javascript工作正常,当我尝试做一个简单的警报('hello');它也可以工作。这真的很令人沮丧,欢迎任何建议!

这是代码笔的链接:http://codepen.io/Pea92/pen/WvrXRY

这段代码对我有用,你应该尝试删除外部.js()

  <head>
  <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
   <script>
   $(document).ready(function(){
   $("button").click(function(){
   $("p").toggle();
  });
});

 $(document).ready(function(){
 $("button").click(function(){
    var div = $("div");  
    div.animate({left: '100px'}, "slow");
    div.animate({fontSize: '3em'}, "slow");
});
});
</script> 
 </head>
 <body>
 <br />

 <button>Click Here</button>
 <p>This is a example of jquery 2.1.1 to show and hide contain on view page                 </p>
 <p> below example for animation effect on dataweb view page with jquery 2.1.1 </p>
  <div style="background:#98bf21;height:100px;width:200px;position:absolute;">Example</div>
    </body>