如何找到锚标记的点击事件?

时间:2014-03-24 15:33:52

标签: javascript jquery html

我想找到锚标记的点击事件,

我试过跟随但没有运气,我做了任何常见的错误

<script type="text/javascript">
         $(function () {


             $('a').on('click', function () {
                 alert('Got you');
             });

         });
     </script>
</head>
<body>
<a href="single-page.html#a1">Link text</a>
<a href="single-page.html#a2">Link text</a>
</body>

1 个答案:

答案 0 :(得分:2)

你的代码没有错。

您可能正在使用旧版本的jquery,它没有.on()。它仅在版本1.7中添加

尝试:

$('a').click(function () {
    alert('Got you');
 });

或者:

$('a').bind('click' , function(){
   alert('Got you');
});