如何使用jQuery检测页面上的第二个链接? [英] How to detect the 2nd link on a page using jQuery?
本文介绍了如何使用jQuery检测页面上的第二个链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的第一个有效,即a:first
检测到第一个链接,但a:second
不能.如何使用jQuery检测页面上的第二个链接?
The first one below works, that is a:first
detects the 1st link, but a:second
doesn't. How can I detect the 2nd link on a page using jQuery?
<script type="text/javascript">
$(document).ready(function() {
$('a:first').click(function() {
alert('you clicked 1st link');
});
$('a:second').click(function() {
alert('you clicked 2nd link');
});
});
</script>
<a href="#">1st Link</a>
<a href="#">2nd Link</a>
推荐答案
您使用 eq()
,就像这样:
You use eq()
, like so:
$('a').eq(1).click(...);
或选择器版本:
$('a:eq(1)').click(...);
它是1
,因为eq
是从0开始的.
It is 1
because eq
is 0-based.
这篇关于如何使用jQuery检测页面上的第二个链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文