0

私は2つのhtmlテーブルを持っています。最初のテーブルで、必要な値を選択して追加ボタンをクリックすると、最初のテーブルのレコードが取得され、2 番目のテーブルに追加されます。また、コンボボックスで値を選択して追加ボタンをクリックすると、コンボボックスで構成される最初のテーブルに td があり、コンボの値に従ってレコードを 2 番目のテーブルに追加できます。つまり、レコードを追加することを意味します。何度も。

私は今、次のことに疑問を持っています:

数値で構成される 2 番目のテーブルにテキスト ボックスがあり、最初のテーブルからレコードを選択して追加すると、行が 2 番目のテーブルに動的に追加され、テキスト ボックスが追加されます。これとは別に、これらのテーブルの外にテキスト ボックスがあります。2 番目のテーブルのテキスト ボックスの値を追加し、これらの html テーブルに属さないテキスト ボックスに合計を表示する必要があります。

jquery を使用した php コード サンプルは次のとおりです。

phpコード

     <div>

        <label>Todays date</label>

        <input type=text name=tdate id=tdate>// used a datepicker for this

        <input type=button class=addBtn>

     <table border=1 id=tbl>

      <tr>

          <th>sno</th>

          <th>name</th>

          <th>date</th>

          <th>insertion</th>

          <th>Amount</th>

     </tr>

     <tr>

         <td id=num>1</td>

         <td id=name>abc</th>

         <td id=date>08-10-2012</td>

         <td><select id=insertion name=insertion>

         <?php for($i=1;$i<=10;$i++) { echo "<option value=$i>$i</option>; }?>

         </select>
         </td>

         <td id=amount>10000</td>

    </tr>

   <tr>

     <td id=num>2</td>

     <td id=name>def</th>

     <td id=date>23-10-2013</td>

     <td>

      <select id=insertion name=insertion>

      <?php for($i=1;$i<=10;$i++) { echo "<option value=$i>$i</option>; }?>

     </select>

     </td>

     <td id=amount>10000</td>

   </tr>

     </table>

// 上記のテーブルデータはデータベースからコンボボックスの onchange イベントと大量のデータを使用して購入されますが、

//現在は表示されていません。

     <table border = 1 id = clone>

   <tr>

    <th>sno</th>

    <th>name</th>

    <th>date</th>

    <th>insertion</th>

    <th>Amount</th>

    <th>today date</th>

  <tr>

</table>


<label>totAmount</label>

<input type = text name= totAmount id=totAmount>

  </div>

functions.js

$('#tbl').on('click', 'tbody tr', function(event) { 

            if ($(this).hasClass('selected')) { 

                $(this).removeClass('selected');

                $(this).css("background", "white");

            } else {       

                $(this).addClass('selected');
                $(this).css("background", "#ffc");                    
            }
});


  var k=1;

  $(".addBtn").on('click', function(event) {

  if ($('#tbl tr').hasClass('selected')) {

      var items = [];

      $('#tbl tr.selected').each(function() {           

                     var name= $(this).find("#name").html();

                     var date = $(this).find("#date").html();

                     var insertion = $(this).find("#insertion option:selected").html();

         var amount = $(this).find("#amount").html();

         var todaydate = document.getElementById("tdate").value;

        for(var j=1; j<=insertion;j++) {

              var n = "<tr>"+"<td>"+k+"</td>"+"<td>"+name+"</td>"+

                  "<td>"+date+"</td>"+"<td>"+j+"</td>"+

                  "<td>"+amount+"</td>"+"<td>"+todaydate+"</td>"+

                    "</tr>";

                items.push(n);

                $("#clone").append(n);

                k++;                

          }
      });
    }
      $("#tbl tr").removeClass('selected');
      $("#tbl tr").css('background','white');
 });

// テキストボックス totAmount があります。

//クローン テーブルに存在する金額を totAmount の金額に追加し、さらに

// 追加ボタンをクリックすると、テーブル (tbl) から tr を選択した後、tr が追加されます

//しかし、金額をテキストボックス totAmount に追加できませんでした。

テーブルからデータをコピーして別のテーブルに追加するのが最善の方法であることを知りたかったのです。

そうでない場合は、あるテーブルから別のテーブルにデータをコピーする他の可能な方法を、例を挙げて教えてください。

ありがとう

助けてください。

4

0 に答える 0