のインデックス値に... ...私は次のコード を使用しています属性
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.
これは、クリックされたときにそのIDを警告するすべて<a>
要素にclick
イベントを割り当てます。
e.preventDefault()
の行のコメントを解除して、リンクのデフォルト動作(href
に従う)を防止します。
それはおそらくリンクにclass属性を追加し、それを使用して選択するのがベストでしょう:
$('a.someClass').click(function(e) {
alert(this.id);
// e.preventDefault(); // Uncomment this line if you don't want
});
これはthe class selectorを使用して、クラス"someClass"
と<a>
要素を選択します。
ここでは、私がread
id
を持っているリンクをターゲットに
attribute-starts-withセレクタを使用
$('a[id^=read]').click(function(){
alert(this.id);
return false;
});
を行きます