Jquery警报消息未弹出

时间:2013-11-11 22:45:09

标签: jquery

我是JQuery的新手并尝试使用此代码但由于某种原因我没有看到弹出警报按钮..

<!doctype html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Demo</title>
    </head>

    <body>
        <a href="http://jquery.com/">jQuery</a>
        <script src="C:/jquery/jquery.js"></script>
        <script>
            $( document ).ready(function() {
                $( "a" ).click(function( event ) {
                    alert( "The link will no longer take you to jquery.com" );
                    event.preventDefault();
                });
            });
        </script>
        <style>
            a.test {
                font-weight: bold;
            }
        </style>
    </body>
</html>

2 个答案:

答案 0 :(得分:2)

我认为这不是从本地主机中包含jquery脚本的正确方法,您可以出于测试目的(甚至是生产)以这种方式包含它:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

请记住在你的html标题中输入。

如果您仍希望将其包含在本地驱动器中,请使用以下路径:

file:///C:/jquery/jquery.js

答案 1 :(得分:0)

代码没问题,这应该有效。

尝试替换

<script src="C:/jquery/jquery.js"></script>

通过

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>