动态添加复选框 [英] Add checkbox dynamically

查看:123
本文介绍了动态添加复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使表格上的复选框可以检查?我有下面的代码通过使用jquery函数动态添加复选框。下面的代码可以动态添加复选框,但问题是函数添加的复选框无法检查(禁用)。

how to make the checkbox on the table can be checked? I've the code below to add the checkbox dynamically by using a jquery function. The code below succeed to add the checkbox dynamically, but the problem is the checkbox added by the function can't be checked (disabled).

<table id="detail">
  <tr>
    <td><input type="checkbox" id="cb" name="cb[]"></td>
  </tr>
</table>

这是用于添加行的按钮:

This is the button to add the row:

<input type="button" id="addRow" value="ADD ROW" />

这是我有的jquery函数:

And this is the jquery function I have:

<script type="text/javascript">
  $(document).ready(function() {
    $("#addRow").click(function() {
      $('#detail tbody>tr:last').clone(true).insertAfter('#detail tbody>tr:last');
    });
  });
</script>

任何人都可以帮助您的代码?感谢...:)

Anyone can help for the code? Thanks... :)

推荐答案

请先修正javascript函数!

Please first correct the javascript function !

  $(document).ready(function() {
    $("#addRow").click(function() {
      $('#detail tbody>tr:last').clone(true).insertAfter('#detail tbody>tr:last');
    });
  });

您的代码适用于我的意思是复选框被选中(只有当你勾选最后一个复选框,将克隆它)

And your code works for me means the checkbox is checked (only if you tick last checkbox then your code will clone it)

查看我的 jsfiddle 或< a href =http://jsfiddle.net/x8rWa/1/ =nofollow> jsfiddle更新

这篇关于动态添加复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆