简体   繁体   中英

I cannot get a piece of code to work outside of jsfiddle

I cannot get this piece of code to work outside of jsfiddle. I dont understand why it doesn't work from my local server.

http://jsfiddle.net/gHb9F/

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title> - jsFiddle demo</title>


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


    <style type='text/css'>
        a, a:visited { color:black }
        a.link.active { color:blue; }
    </style>




    <script type='text/javascript'>//<![CDATA[
    $(window).load(function(){
        $(function() {
            $('a.link').click(function() {
                $('a.link').removeClass('active');
                $(this).addClass('active');
            });
        });
    });//]]>

    </script>

</head>
<body>
<a href="#" class="link">Link 1</a>
<a href="#" class="link">Link 2</a>

</body>

</html>

What am I doing wrong?

可能您没有将jQuery链接正确地包含到html中,请尝试将此行添加到您的头部:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM