开发者

How to click a specific link with jQuery

I'm trying to simply click a link whenever someone开发者_JAVA技巧 presses the right arrow key, but nothing is happening.

I've got this link:

<a title="party pics! 16" href="/photos/photo/new-party-pics-16/" id="next-in-gallery">
    <img src="http://localhost/static/photologue/photos/cache/thumbnail16.jpg">
</a>

and this jQuery:

<script type="text/javascript">
    $(document).keydown(function(e){
        if (e.keyCode == 39) { 
           $("a#next-in-gallery").click();
           return false;
        }
    });
</script>

Seems to do nothing, though. Thoughts?


How about

<script type="text/javascript">
    $(document).keydown(function(e){
        if (e.keyCode == 39) { 
           document.location.href = $("a#next-in-gallery")[0].href;
           return false;
        }
    });
</script>

?


$("a#next-in-gallery").trigger('click');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜