jQuery函数没有'在CDN脚本标记中未按预期运行

jQuery function doesn't run as expected inside CDN script tag

本文关键字:运行 脚本 CDN 函数 jQuery      更新时间:2023-09-26

这是代码。我已经结束了Arch Linux,如果这是一件重要的事情。。。我厌倦了在jquery的网站上尝试不同的本地库,但它不起作用。。。

    <!doctype html>
    <html>
    <meta charset="utf-8" />
        <head>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" type="text/javascript">
                $(document).ready(function(){
                    $("#header").hide();
                    $("#header").fadeIn(2000);
                });
            </script>
            <title>1</title>
        </head>
        <body>
            <h1 id="header" align="center">Page content</h1>
            <p align="center">
                Footer
            </p>
        </body>
    </html>

将jQuery调用和自定义脚本放在单独的标记中。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
    $(document).ready(function() {
        $("#header").hide();
        $("#header").fadeIn(2000);
    });
</script>

请注意,使用HTML5,您不需要为JavaScript指定类型。

使用script标记的方式错误!

确保将jQuery代码正确地封装在<script></script>块中。同时关闭所有打开的script块。

这应该工作

<!doctype html>
<html>
<meta charset="utf-8" />
    <head>
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
          <script type="text/javascript">
            $(document).ready(function(){
                $("#header").hide();
               $("#header").fadeIn(2000);
            });
        </script>
        <title>1</title>
    </head>
    <body>
        <h1 id="header" align="center">Page content</h1>
        <p align="center">
            Footer
        </p>
    </body>
</html>

工作样品