【问题标题】:jQuery checkbox undo solutionjQuery复选框撤消解决方案
【发布时间】:2011-04-14 09:28:02
【问题描述】:
<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 实现这一点

【问题讨论】:

    标签: jquery jquery-ui jquery-selectors jquery-validate


    【解决方案1】:

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

    示例: 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;
        });
    });​
    

    【讨论】:

    • 我想获得在第二个 td 中选中的复选框。在撤消时将其放回第一个 td 中的原始位置
    • @Hulk - 你是说当有人选中一个复选框时,整个复选框应该移动到第二个&lt;td&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    • 2011-10-23
    • 2011-06-15
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多