jQuery 复选框撤消解决方案

发布于 2024-09-24 05:31:33 字数 609 浏览 0 评论 0原文

<table> 
  <tr>
   <td>
    <div>
     <input type="checkbox" id="home1">Home1</input>
     <input type="checkbox" id="home2">Home3</input>
     <input type="checkbox" id="home3">Home3</input>
     <input type="checkbox" id="home4">Home4</input>
   </div>
  </td>
  <td id="selectedhome"> </td>
 </tr>
</table>

<input type="button" value="Select" />

在上面的代码中,单击按钮时,复选框的所有选定值都应出现在 selectedhome td 中,旁边有一个撤消链接,并且从第一个 td 中不可见。选择撤消按钮时,复选框应返回到初始状态位置。如何使用 jquery 实现此目的

<table> 
  <tr>
   <td>
    <div>
     <input type="checkbox" id="home1">Home1</input>
     <input type="checkbox" id="home2">Home3</input>
     <input type="checkbox" id="home3">Home3</input>
     <input type="checkbox" id="home4">Home4</input>
   </div>
  </td>
  <td id="selectedhome"> </td>
 </tr>
</table>

<input type="button" value="Select" />

In the above code onclick of the button all the selected values of the check box should appear in the selectedhome td with a undo link next to to it and be invisible from the first td.Onselect the undo button the checkbox should go back to the initial position.How to achieve this using jquery

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何必那么矫情 2024-10-01 05:31:33

尝试一下。它将每个复选框重置为页面加载时的默认选中值。

示例: http://jsfiddle.net/6kFMk/1/

  // Display ID value of checked boxes
$('input[value=Select]').click(function() {
    var values = $('table :checkbox:checked').map(function() {
        return this.id;
    }).get().join(',');
    var home = $('#selectedhome').text(values);
});

  // Reset checkboxes to initial state
$('input[value=Undo]').click(function() {
    $('table :checkbox').each(function() {
        this.checked = this.defaultChecked;
    });
});​

Give this a try. It will reset each checkbox to the default checked value it had when the page loaded.

Example: http://jsfiddle.net/6kFMk/1/

  // Display ID value of checked boxes
$('input[value=Select]').click(function() {
    var values = $('table :checkbox:checked').map(function() {
        return this.id;
    }).get().join(',');
    var home = $('#selectedhome').text(values);
});

  // Reset checkboxes to initial state
$('input[value=Undo]').click(function() {
    $('table :checkbox').each(function() {
        this.checked = this.defaultChecked;
    });
});​
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文