这段代码有什么不对吗?

时间:2011-01-27 06:10:24

标签: asp.net jquery html

大家好,我是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>

1 个答案:

答案 0 :(得分:10)

您无法为<script>使用自我结束标记。您必须以</script>

结尾
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script>
相关问题