jQuery / Javascript根本不起作用......我迷路了

时间:2013-01-04 04:31:53

标签: javascript jquery

出于某种原因,jQuery和Javascript在我的网站上无效。

见这里:http://hellomynameisad.am/test.html

有人能够达到巅峰并让我知道自己错过了什么吗?我尝试了很多不同的jQuery代码,似乎没什么用。谢谢。

2 个答案:

答案 0 :(得分:3)

您需要将document.ready设置为使html元素能够执行javascript,或者您可以在结束正文标记之前放置脚本。

<强> Live Demo

$(document).ready(function(){
  $("#container").fadeOut(function() {
     $(this).text("World").fadeIn();
  });
});

编辑:我发现html中的其他错误很少见。

  1. 没有起始身体标签。
  2. 将脚本放在head标签之间或在关闭body标签之前。
  3. 在javascript脚本标记中添加类型属性。
  4. 最好使用http:
  5. 为jquery的url加前缀

    更改HTML

    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
          <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js"></script>
          <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.js ">     </script>
          <title>Untitled Document</title>
          <style type="text/css"> </style>
    
    <script type="text/javascript">
    
        $(document).ready(function(){
            $("#container").fadeOut(function() {
                $(this).text("World").fadeIn(); 
            });
        });    
    </script>    
    </head>
    <body>
        <div id="container">Hello</div>​
    </body>
    </html>
    

答案 1 :(得分:-3)

请添加此

<script>
  $(document).ready(function(){
     $("#container").fadeOut(function() {
        $(this).text("World").fadeIn();
     });
  });
</script>

</body>结束后看到它运行的部分代码。