<table class="table"> <tbody> <tr> <th>項目1</th> <th>項目2</th> <th>項目3</th> <th>項目4</th> <th>項目5</th> <th>項目6</th> <th>項目7</th> <th>項目8</th> <th>項目9</th> </tr> <tr> <td><span>13</span></td> <td>C1</td> <td>C2</td> <td>C3</td> <td>C4</td> <td>C5</td> <td>C6</td> <td><input type="button" value="B1" onclick="location.href='/hoge/13'" /></td> <td><input type="button" value="B2" onclick="location.href='/foo/13'" /></td> <td><input type="button" value="Pv" class="Pv" /></td> </tr> <tr> <td><span>12</span></td> <td>C1</td> <td>C2</td> <td>C3</td> <td>C4</td> <td>C5</td> <td>C6</td> <td><input type="button" value="B1" onclick="location.href='/hoge/12'" /></td> <td><input type="button" value="B2" onclick="location.href='/foo/12'" /></td> <td><input type="button" value="Pv" class="Pv" /></td> </tr> <tr> <td><span>11</span></td> <td>C1</td> <td>C2</td> <td>C3</td> <td>C4</td> <td>C5</td> <td>C6</td> <td><input type="button" value="B1" onclick="location.href='/hoge/11'" /></td> <td><input type="button" value="B2" onclick="location.href='/foo/11'" /></td> <td><input type="button" value="Pv" class="Pv" /></td> </tr> </tbody> </table>
というテーブルで各行のPvのClass が付与されたボタンを押すとindex番号を取得して、その行の先頭の番号を取得しようとしています。
$('.Pv').click(function(){ var index = $(".Pv").index(this); alert("index=" + index); var text = $("span:eq(" + index + ")").text(); alert("text=" + text); });
上手くいきません。
どこが悪いでしょうか????
ご指摘頂けば幸いです。
回答3件
あなたの回答
tips
プレビュー