2011-01-27 30 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

VS VS与此有什么关系?它是不是一个html页面? – 2011-01-27 06:13:53

+0

是的,我在VS里做这个例子。我也提到过。 – 2011-01-27 06:14:38

回答

10

您不能对<script>使用自闭合标签。您必须以</script>结尾:

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