如何在我的HTML文档中添加jQuery(在线或离线)?

时间:2021-12-05 18:56:41

This is my html; for some reason it is not working.

这是我的HTML;由于某种原因它不起作用。

            <!DOCTYPE html>
            <html lang="en">
                    <head>
                        <meta charset="utf-8" />
                        <title></title>
                        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js">

                        </script>
                    </head>
                        <body>
                            <div id="container">
                                <h2></h2>
                            </div>
                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js">
                                $(document).ready(function() {
                                    $("h2").html("Hello there!");
                                });
                            </script>
                        </body>
            </html>

I am new to jQuery so sorry if I am making a blatantly ignorant mistake.

我是jQuery的新手,很抱歉,如果我犯了一个明显无知的错误。

1 个解决方案

#1


2  

You just need to remove the src attribute from the script block:

您只需要从脚本块中删除src属性:

  <script>
          $(document).ready(function() {
                 $("h2").html("Hello there!");
          });
  </script>

This is because otherwise your browser will use the script specified in the src attribute rather than in its containing block

这是因为否则您的浏览器将使用src属性中指定的脚本而不是其包含块中的脚本

#1


2  

You just need to remove the src attribute from the script block:

您只需要从脚本块中删除src属性:

  <script>
          $(document).ready(function() {
                 $("h2").html("Hello there!");
          });
  </script>

This is because otherwise your browser will use the script specified in the src attribute rather than in its containing block

这是因为否则您的浏览器将使用src属性中指定的脚本而不是其包含块中的脚本