2013-11-08 4 views
0

Я только начинаю с jQuery, и я застрял на базовом примере. Я использую Safari для этого примера.jQuery: TypeError 'undefined'is не является функцией

01.js:

$(document).ready(function() { 

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

}); 

first.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 веб-программирование, я получаю ошибку "JQuery: TypeError«undefined'is не функция" возвращается на .addclass ('highlight'), и, похоже, он не запускал .js, который я запросил.

Может кто-нибудь просветить меня на том, что я делаю неправильно здесь! Спасибо за помощь!

+3

Javascript с учетом регистра, 'addclass' отличается от' addClass'. – leaf

+0

попробуйте использовать лучший редактор, так как я не знаю, какой из них вы используете. Советую использовать WebStorm от jetbrains. удачи –

+0

@Abderrazakk Он упомянул, какой редактор он использует? – ediblecode

ответ

2

addclass() должно быть addClass()

1

Вам необходимо использовать addClass('highlight') не addclass('highlight'), обратите внимание, что это случай с верблюдом и не нижний чехол.

Кроме того, я считаю, что это не является основной причиной вашей ошибки, и это может быть, что в вашем скрипте вы должны заменить $ с jQuery:

jQuery(document).ready(function() { 

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

}); 

Reference

+0

Хотя вы правы, я не думаю, что это большая проблема, так как вы получите 'непризнанную функцию 'addclass'' –

+0

Или может быть **' Объект [объект Object] не имеет метода addclass '** ** –

+0

@RoryMcCrossan Я знаю. Я добавляю к моему ответу в настоящее время для других проверок. Эта часть - это только первая часть, которую я заметил неправильно. – ediblecode

0

Попробуйте следующее

$(document).ready(function() { 

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

}); 
Смежные вопросы