从两个表行(tr)中选择数据

时间:2017-10-10 15:59:23

标签: jquery html html-table textarea tr

我希望点击Addtd的{​​{1}},Javascript / JQuery会从定位的textarea中选择此trid紧接着那个id [不是所有textarea] .....

HTML

val()

JS

                <tr>
                    <td>A</td>                  
                    <td>£ 10</td>
                    <td><b id='1' class='btn'>Add</b></td>
                </tr>

                <tr>
                    <td>
                      <div class='form-group'>
                        <label>Add Note:</label>
                        <textarea class='form-control'></textarea>
                      </div>
                    </td>
                </tr>

               <tr>
                    <td>B</td>                  
                    <td>£ 10</td>
                    <td><b id='2' class='btn'>Add</b></td>
                </tr>

                <tr>
                    <td>
                      <div class='form-group'>
                        <label>Add Note:</label>
                        <textarea class='form-control'></textarea>
                      </div>
                    </td>
                </tr>


                <tr>
                    <td>C</td>                  
                    <td>£ 10</td>
                    <td><b id='3' class='btn'>Add</b></td>
                </tr>

                <tr>
                    <td>
                      <div class='form-group'>
                        <label>Add Note:</label>
                        <textarea class='form-control'></textarea>
                      </div>
                    </td>
                </tr>

1 个答案:

答案 0 :(得分:1)

note更改为:

var note = $(this).closest('tr').next().find('textarea').val();