的索引值我使用下面的代码 ... ...属性
for($i=0; $i<90; $i++){
?>
<a id='read[<?php print $i; ?>]' href="<?php print $textToshow; ?>"> Text Shown</a>
<?php } ?>
我想知道在href的ID时,就可以了用户点击。像读取的东西[1]读[2]等
的索引值我使用下面的代码 ... ...属性
for($i=0; $i<90; $i++){
?>
<a id='read[<?php print $i; ?>]' href="<?php print $textToshow; ?>"> Text Shown</a>
<?php } ?>
我想知道在href的ID时,就可以了用户点击。像读取的东西[1]读[2]等
$('a').click(function(e) {
alert(this.id);
// e.preventDefault(); // Uncomment this line if you don't want
}); // to follow the link's href.
此分配click
事件所有<a>
元件点击时将提醒其ID。
取消注释e.preventDefault()
行以防止链接的默认行为(在其href
之后)。
这很可能是最好的一类属性添加到链接,并选择使用:
$('a.someClass').click(function(e) {
alert(this.id);
// e.preventDefault(); // Uncomment this line if you don't want
});
这将选择<a>
元素使用the class selector类"someClass"
。
在这里你去
$('a[id^=read]').click(function(){
alert(this.id);
return false;
});
我用attribute-starts-with选择的目标是有一个id
与read