-1

私は2つと3つの列text_fieldsを持っていtableます。ボタンをクリックしてtext_field、最初の 2 列のテーブルにその 2 つの値を追加します。そのため、ユーザーはtext_field値を何度も変更でき、[追加] をクリックして値を次の行に追加できbuttonます。

2つtext_fieldsは次のとおりです。

<input class="cross-reference-question-value" type="text" style="border: 1px solid gray;  ">
<input class="cross-reference-answer-value" type="text" style="border: 1px solid gray;  ">

こちらがtable

<table class="gridView" id="selected_units">
  <thead>
    <tr class="gridViewHeader">
      <th>Question</th>
      <th>Answer</th>
      <th>Action</th>
    </tr>
  </thead>

  <tbody> 
    <tr class="<%= cycle('gridViewclickableRowDialog', 'gridViewAltclickableRowDialog') %>">
      <td></td>
      <td></td>
      <td><a href="#">Delete</a></td>
    </tr>
  </tbody>
</table>

button_linkは_

<a href="#" , class="button" >hello</a>

ありがとう!!

4

1 に答える 1

1

これから始めてみてください:

​$('.button').click(function() {
    var question = $('.cross-reference-question-value').val();
    var answer = $('.cross-reference-answer-value').val();
    var newrow = '<tr><td>' + question + '</td><td>' + answer + '</td></tr>';
    $('#selected_units tr:last').after(newrow);
});​​​​​

デモを確認してください。空の入力、重複行などのチェックを追加します。

于 2012-10-16T20:58:06.880 に答える