开发者

jQuery checkbox undo solution

开发者_开发问答
<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


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;
    });
});​
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜