4

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

我似乎无法让 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,但我确信它应该可以工作。

非常感谢您!

4

3 回答 3

3

如果那是您的最终代码,那么您就错过了})

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

假设这是您的问题,我建议您始终使用正确的缩进。它确实有助于轻松检测此类问题。

于 2013-07-29T23:51:25.060 回答
1
<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>

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

于 2013-07-30T00:17:50.240 回答
0
change the path to <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script> . 
于 2013-07-30T02:14:23.983 回答