doucha7329 2015-11-14 13:03
浏览 56
已采纳

单击按钮后将php td值插入textarea

I have echo PHP table with 3 tds: 1- checkbox. 2- names. 3- phone Numbers

I made textarea to contain all checked checkboxes tds phone Numbers into it.

I tried to modificate this code but it doesn't work with me.

My code :

<table class="table table-striped table-bordered TableStyle" id="table-scroll ">
    <thead>
        <th class="thead"><input type="checkbox" name="checkallnum" value="" id="checkallnum2" /></th>
        <th class="thead">Name</th>
        <th class="thead">Phone</th>
    </thead>
    <tbody>
        <tr>
             <td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
             <td>AMMAR</td>
             <td>123456789</td>
        </tr>
         <tr>
             <td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
             <td>Sara</td>
             <td>987654321</td>
        </tr>
    </tbody>
 </table>

<button type="button" id="confirmNums" class="btn btn-primary pull-left" style="">Add</button>

<textarea rows="8" name="" id="sendToNum" class="form-control" style="margin-bottom: 10px;" tabindex="1"></textarea>
  • 写回答

1条回答 默认 最新

  • donjd86266 2015-11-14 13:50
    关注

    A possible solution is to use jQuery.

    Maybe this example can get you started. When you click the 'Add' button, the phonenumbers will be added to the textarea.

    $(document).ready(function() {
      $('#confirmNums').click(function() {
        var newline = "
    ";
        var sendToNum = $('#sendToNum');
        sendToNum.text('');
        $("input[name=check]:checked").each(function() {
          var phoneNumber = $(this).parent().nextAll('td').eq(1).html();
          sendToNum.append(phoneNumber + newline);
        });
      });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table class="table table-striped table-bordered TableStyle" id="table-scroll ">
        <thead>
        <th class="thead"><input type="checkbox" name="checkallnum" value="" id="checkallnum2" /></th>
        <th class="thead">Name</th>
        <th class="thead">Phone</th>
        </thead>
        <tbody>
        <tr>
            <td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
            <td>AMMAR</td>
            <td>123456789</td>
        </tr>
        <tr>
            <td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
            <td>Sara</td>
            <td>987654321</td>
        </tr>
        </tbody>
    </table>
    
    <button type="button" id="confirmNums" class="btn btn-primary pull-left" style="">Add</button>
    
    <textarea rows="8" name="" id="sendToNum" class="form-control" style="margin-bottom: 10px;" tabindex="1"></textarea>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决