2011-01-27 19 views
2

こんにちは皆私はjQueryを初めて使用しています。学習中に私はこのリンクに従います: http://api.jquery.com/browser/。 VS 2010でこの例を実行しようとすると、正確な出力が得られません。しかし、私はこのリンクにあるコードをコピーしていたときに正しい出力を得ていました。誰にでも助けてくれますか?このコードで何が間違っていますか?

<!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> 
     <base href="http://docs.jquery.com" /> 
     <title>index(subject) function</title> 
     <style type="text/css"> 
      .div_style 
      { 
       background-color: Aqua; 
       font-family: Verdana; 
       font-size: small; 
      } 
     </style> 
     <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js" /> 
     <script type="text/javascript"> 
      $(document).ready(function() { 
       $("div.div_style").click(function() { 

        //This is the DOM element clicked 
        var index = $("div").index(this); 
        $("span").text("That was div index #" + index); 
       }); 
      }); 
     </script> 
    </head> 
    <body> 
     <span></span> 
     <br /> 
     <div class="div_style "> 
      First Div 
     </div> 
     <br /> 
     <div class="div_style "> 
      Second Div 
     </div> 
     <br /> 
     <div class="div_style "> 
      Third Div 
     </div> 
     <br /> 
    </body> 
</html> 
+0

これと何が関係しますか?それはhtmlページですか? –

+0

はい、私はVSでこの例をしています。私はそれも言及しています。 –

答えて

10

<script>に自己終了タグを使用することはできません。 </script>で終了する必要があります。

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script> 
+0

ありがとうございました。あなたは素晴らしいです。 –

+0

@enjoy、あなたは大歓迎です。 –

関連する問題