Jquery 属性的索引值

Jquery 属性的索引值,jquery,fancybox,Jquery,Fancybox,我正在使用以下代码 ... $('a').click(function( e ) { alert(this.id); // e.preventDefault(); // Uncomment this line if you don't want }); // to follow the link's href. $i=0;$i的 我想知道用户点击a href时它的id。比如read[1]read[2]等等 $('a').clic

我正在使用以下代码 ...

$('a').click(function( e ) {
   alert(this.id);
   // e.preventDefault(); // Uncomment this line if you don't want
});                       //    to follow the link's href.
$i=0;$i的

我想知道用户点击a href时它的id。比如read[1]read[2]等等

$('a').click(function( e ) {
   alert(this.id);
   // e.preventDefault(); // Uncomment this line if you don't want
});                       //    to follow the link's href.
这将为所有
行分配一个
单击
事件,以防止链接的默认行为(在其
href
之后)

$('a').click(function( e ) {
   alert(this.id);
   // e.preventDefault(); // Uncomment this line if you don't want
});                       //    to follow the link's href.
最好向链接添加一个class属性,然后选择使用该属性:

$('a').click(function( e ) {
   alert(this.id);
   // e.preventDefault(); // Uncomment this line if you don't want
});                       //    to follow the link's href.
$('a.someClass').click(function( e ) {
   alert(this.id);
   // e.preventDefault(); // Uncomment this line if you don't want
});  
这将选择

在这里

$('a').click(function( e ) {
   alert(this.id);
   // e.preventDefault(); // Uncomment this line if you don't want
});                       //    to follow the link's href.
$('a[id^=read]').click(function(){
  alert(this.id);

  return false;
});
我使用选择器来定位具有
id
且以
read
开头的链接

$('a').click(function( e ) {
   alert(this.id);
   // e.preventDefault(); // Uncomment this line if you don't want
});                       //    to follow the link's href.