0

foreach ループによって行が生成されるテーブルがあります。

テーブルの各行には 2 つの列があり、1 つはフォーム、もう 1 つはフォームから送信されたデータ (メモと呼びます) です。(ブラウザを更新せずに jQuery ライブラリを使用して更新します)。

<script>
    $(".notes_column").each(function(){

            var $myform = $(this).find('.notes_form');
            var $mynotes = $(this).find('.notes');

            $myform.validate({
                submitHandler: function(form) {
                    $.post('process.php', $myform.serialize(), function(data) {
                        $mynotes.html(data);
                    });
                }
            });


    }); // each function
</script>


<table id="myTable" class="tablesorter" border="1" cellpadding="5">
<thead> 
    <tr>
        <th>Notes</th>
        <th>Submit Note</th>
    </tr>
</thead>
<tbody>
<?php
    foreach($myarray as $myvar){
        echo ' 
            <tr>
                <td>ID LIKE TO PLACE THE content of the div class="notes"  HERE, HOW CAN I DO IT?</td>
                <td class="notes_column">
                    <form class="notes_form" action="" method="post">
                        <input class="q" type="text" name="notes" size="30" placeholder="Place your notes here..." />
                        <input class="searchsubmit" type="submit" name="submit" value="Submit" />
                    </form>
                    <div class="notes"></div>
                </td>
            </tr>
        ';
    }
?>
</tbody> 
</table>

現在、各テーブル列を反復するjQueryの各関数を使用し、クラス名「.notes_column」の列ごとに、送信されたデータをクラス「notes」でdivに入力します。

質問は大文字でコード内にリストされています。他の列にフォーム送信データを入力するにはどうすればよいですか?

何か案は?

タイ

4

2 に答える 2

0
I would create a <div> in the first <td> such as

<td>
    <div class="put_notes_here">ID LIKE TO PLACE THE content of the div class="notes"  HERE, HOW CAN I DO IT?</div>
</td>

Then populate it the same as you did before
$mynotes.closest("tr").find(".put_notes_here").html(data);
于 2013-01-21T22:01:43.477 に答える
0

each のセレクターを $('#myTable tr') に変更すると、テーブル内のそれぞれを反復処理できます。

次に、tr オブジェクトで each を実行して各 td にアクセスするか、後続のセレクターで jQuery の :first-child および nth-child(2) などを使用できます。

于 2013-01-21T21:46:03.597 に答える