Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我的jQuery赢了';在我的代码中根本不起作用_Javascript_Jquery - Fatal编程技术网

Javascript 我的jQuery赢了';在我的代码中根本不起作用

Javascript 我的jQuery赢了';在我的代码中根本不起作用,javascript,jquery,Javascript,Jquery,我花了几天时间四处寻找,试图弄明白为什么我的jQuery不能在外部文件中工作,或者根本不能工作。我的jQuery本身看起来不错,但文件中的某些东西把它搞砸了。这是我的密码: HTML: 您在哪里编写javascript内容?在一个单独的文件中? 确保将其链接到HTML文件中,与jQuery相同 <script src="yourCode.js"></script> 此外,尽量避免在文件名中使用空格,例如:“something css”与“something_css”

我花了几天时间四处寻找,试图弄明白为什么我的jQuery不能在外部文件中工作,或者根本不能工作。我的jQuery本身看起来不错,但文件中的某些东西把它搞砸了。这是我的密码:

HTML:


您在哪里编写javascript内容?在一个单独的文件中? 确保将其链接到HTML文件中,与jQuery相同

<script src="yourCode.js"></script>


此外,尽量避免在文件名中使用空格,例如:“something css”与“something_css”。

您的代码运行良好。确保正确添加了jQuery库

$(文档).ready(函数(){
$(“#某物”)。单击(函数(){
$('something').fadeOut('slow');
});
});
什么{
高度:100px;
宽度:100px;
填充:10px;
框大小:边框框;
背景色:#EFEF;
颜色:#000;
显示器:flex;
证明内容:中心;
对齐项目:居中;
}

淡出

某物
你好
jQuery(文档).ready(函数(){
jQuery(“#某物”)。单击(函数(){
jQuery(“#something”).fadeOut('slow');
}); 
}); 

您应该将脚本或其链接附加到HTML页面!您正在加载javascript吗?。。。在您共享的HTML中应该有另一个
。+确保JQuery库加载成功,同时打开控制台(开发人员工具)以确定错误。您的代码工作正常。改为尝试使用CDN jQuery。
    <body>
    <div id="something">Hi</div>
    </body>
</html>
$(document).ready(function(){
 $('#something').click(function(){
     $('#something').fadeOut('slow');
 }); }); 
<script src="yourCode.js"></script>
<!DOCTYPE html>
<html>
    <head>
        <title>Something</title>
        <script src="jquery3.2.0.min.js"></script>
         <link rel='stylesheet' type='text/css' href='something-css.css'/>
    </head>

    <body>
    <div id="something">Hi</div>
    <script>
      jQuery(document).ready(function(){
          jQuery('#something').click(function(){
              jQuery('#something').fadeOut('slow');
          }); 
      }); 
   </script>
    </body>
</html>