属性的索引值 [英] the index value of attribute
本文介绍了属性的索引值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码
...
...
I am using the following code ... ...
for($i=0; $i<90; $i++){
?>
<a id='read[<?php print $i; ?>]' href="<?php print $textToshow; ?>"> Text Shown</a>
<?php } ?>
我想知道用户点击它时a href的id。像读[1]读[2]等
I want to know the id of the a href when a user clicks on it. Something like read[1] read[2] etc
推荐答案
$('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。
This assigns a click
event to all <a>
elements that will alert its ID when clicked.
取消注释< a href =http://api.jquery.com/event.preventdefault/\"rel =nofollow> e.preventDefault()
行以防止链接的默认行为(在 href
之后)。
最好添加一个类属性到链接,然后选择使用:
It would probably be best to add a class attribute to the links, and select using that:
$('a.someClass').click(function( e ) {
alert(this.id);
// e.preventDefault(); // Uncomment this line if you don't want
});
这会选择< a>
元素使用类选择器someClass a>。
This selects <a>
elements with the class "someClass"
using the class selector.
这篇关于属性的索引值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文