jQuery未与HTML文件链接

jQuery not linking with HTML file

本文关键字:链接 文件 HTML 未与 jQuery      更新时间:2023-09-26

我正在学习编程,遇到了一些本应非常简单但却让我沮丧了三天的事情。

我似乎无法让jQuery文件与我的html链接。

这是我的HTML:

<html>
<head>
    <title>Title</title>
    <link type="text/css" rel="stylesheet" href="stylesheet.css"/>
    <script src="/jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="/script.js"></script>
</head>     
    <body>
    <div class="heads">
        <div id="about">
            <p>About.</p>
        </div>
        <div id="work">
            <p>Work.</p>
        </div>
        <div id="contact">
            <p>Contact.</p>
        </div>
    </div>
    </body>

这是jQuery:

$(document).ready(function() {
    $('div').click(function() {
        $(this).fadeOut('fast');
    });
});

这不是最后的jQuery,但我确信它应该是有效的。

提前感谢您!

如果这是您的最终代码,那么您就缺少})

$(document).ready(function() {
    $('div').click(function() {
        $(this).fadeOut('fast');
    }); // < -- This is missed
});

假设这是您的问题,我建议您始终使用正确的缩进。它确实有助于轻松地发现这些问题。

<script src="/jquery-2.0.3.min.js"></script>
<script src="/script.js"></script>

文件的路径错误。您不使用任何子文件夹。应该是:

<script src="jquery-2.0.3.min.js"></script>
<script src="script.js"></script>

这为我解决了问题:)愉快编码

change the path to <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script> .