如何动态在onclick最后一列中使用Jquery添加新的行HTML表

时间:2015-09-04 06:36:43

标签: javascript jquery

  

如何设置“添加行”单击“最后一列”   柱

Here Is Example http://jsfiddle.net/83aqdd62/8/

enter image description here

http://jsfiddle.net/83aqdd62/8/此处示例

1 个答案:

答案 0 :(得分:2)

Updated Fiddle

<table id="sampTable">
      <thead>
        <tr>
            <td>Column 1</td>
            <td>Column 2</td>
            <td>Column 3</td>

          </tr>
      </thead>
      <tbody>
         <tr>
              <td><input type="text"/></td>
              <td><input type="text"/></td>
             <td><input type="text"/></td>

         </tr>
          <tr>
              <td><input type="text"/></td>
              <td><input type="text"/></td>
              <td><input type="text"/></td>

         </tr>
      </tbody>
    </table>

Jquery的

$('#sampTable tr td:last-child').on("click",function(){
   addRow();
});
function addRow(){
     $sampleRow = $(' <tr> <td><input type="text"/></td><td><input type="text"/></td> <td><input type="text"/></td></tr>');
    $sampleRow.find("td:last").click(function(){
       addRow();
    });
   $('#sampTable tbody').append($sampleRow);
}