0

我刚开始使用 jQuery,我被困在一个基本的例子上。我在这个例子中使用 Safari。

01.js:

$(document).ready(function() {

    $('div.poem-stanza').addclass('highlight');

});

第一个.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Through the Looking-Glass</title>
<link rel="stylesheet" href="script/01.css">
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script language="javascript" src="01.js"></script>
</head>
    <h1>Through the looking-Glass</h1>
    <div class="author">by Lewis Caroll</div>
    <div class="chapter" id="chapter-1">
        <h2><class="chapter-title">1. Looking-Glass House</h2>
        <p>There was a book lying near Alice on the table, and while she sat watching the White Kind (for she was still a little anxious about him, in case he fainted again), she turned over the leaves, to find some part that she could read, <span class="spoken">"&mdash;for it's all in some language I don't know,"</span> she said to herself.</p>
        <p>It was like this.</p>
        <div class="poem">
            <h3><class="poem-title">YKCOWREBBAJ</h3>
            <div class="poem-stanza">
                <div>Sevot yhtils eht dna ,gillirb sawT'</div>
                <div>;ebaw eht ni elbmig dna eryg diD</div>
                <div>, sevogorob eht erew ysmim llA</div>
                <div>.ebargtuo shtar emom eht dnA</div>
            </div>
        </div>
        <p>She puzzled over this for some time, but at last a bright thought struck her. <span class="spoken">"Why, it's a looking-glass book, of course! And if I hold it up against a glass, the words will al go the right way again."</span></p>
        <p>This as the poem that Alice read.</p>
        <div class="poem">
            <h3 class="poem-title">JABBERWOCKY</h3>
              <div class="poem-stanza">
                    <div>'Twas brillig, and the slithy toves</div>
                    <div>Did gyre and gimble in the wabe;</div>
                    <div>All mimsy were the borogoves,</div>
                    <div>And the mome raths outgrabe.</div>
                </div>  
            </div>
        </div>
<body>
</body>
</html>

在 Safari 网络开发工具包中,我在 .addclass('highlight') 上返回错误“jQuery: TypeError 'undefined' is not a function”,并且似乎无法运行我请求的 .js。

有人可以告诉我我在这里做错了什么!谢谢您的帮助!

4

3 回答 3

2

addclass()应该addClass()

于 2013-11-08T10:57:33.613 回答
1

您需要使用addClass('highlight')not addclass('highlight'),注意它是驼峰式而不是小写。

此外,我认为这不是您错误的主要原因,可能是在您的脚本中您必须替换$jQuery

jQuery(document).ready(function() {

    jQuery('div.poem-stanza').addClass('highlight');

});

参考

于 2013-11-08T10:56:50.597 回答
0

试试这个

$(document).ready(function() {

    $('div.poem-stanza').addClass('highlight');

});
于 2013-11-08T10:58:34.663 回答