2

テーブル行に id を持つボタンがありますbtn_number_$irow_$iボタンをクリックすると、最初は非表示になっているid を持つテーブル行を表示したいと思います。

2 つのテーブル行を作成するための PHP コードを次に示します。

echo "<tr><td>"."<button id= \"btn_number_$i\"  class='btn info toggler' >Info   <i class='icon-arrow-down'></i></button>"."</td></tr>";
echo "<tr id='row_$i' class='info_row'><td>Hello There!!</td></tr>";

以下は私のjQueryコードです。同様の名前の行IDを作成して実行しようとし.showています。しかし、私は望ましい結果を得ていません。

$(function () {
    $('.info_row').hide(); // first I need to hide all the second rows.
    $('.toggler').click(function () {
        var currentId = $(this).attr('id');
        console.log(currentId);
        var lastChar = currentId.substr(currentId.length - 1); //Herein I am trying to extract the last character from btn_number_$i which is $i and then appending it with 'row_'
        var rowId = 'row_' + lastChar;
        console.log(rowId); // I am able to get the current value in console log.
        $('#rowId').show(); // But even after all that i am not able to show the element.
    });
});

どんな助けでも感謝します。

4

1 に答える 1

3

rowId作成した id を含む変数を使用していませんがrowId、文字列リテラルを使用しています。あなたが持っているセレクターは、要素を探しますid = rowId

変化する

$('#rowId').show();

$('#' + rowId).show();
于 2013-03-12T07:08:46.903 に答える