2012-07-06 72 views
0

改变复选框的ID我有以下html获取所有从默认设置

<table id="share">       
     <tr class="row"> 
       <td class="optionsCell">Share Clip postings : </td> 
       <td class="cell"><input type="checkbox" id="shareClipPost" /><span>Yes</span></td> 
     </tr> 
     <tr class="row"> 
       <td class="optionsCell">Share my favorites : </td> 
       <td class="cell"><input type="checkbox" id="shareFavorites" /><span>Yes</span></td> 
     </tr> 
     <tr class="row"> 
       <td class="optionsCell">Share all ratings given/changed : </td> 
       <td class="cell"><input type="checkbox" id="shareRating" /><span>Yes</span></td> 
     </tr> 
     <tr class="row"> 
       <td class="optionsCell">Share all shows recorded : </td> 
       <td class="cell"><input type="checkbox" id="shareRecorded" /><span>Yes</span></td> 
     </tr> 
     <tr class="row"> 
       <td class="optionsCell">Share all shows viewed : </td> 
       <td class="cell"><input type="checkbox" id="shareView"/><span>Yes</span></td> 
     </tr> 
</table>   

现在我想达到什么是适当的方式,这样我可以得到哪些复选框被选中或选中。最初我标记检查从ajax请求获得的数据复选框,其余的其他框保持未选中状态。这是在我的设置。因此,现在我需要找到一种方法来获取仅用户更改的复选框的值可能会取消选中先前选中的复选框或选中任何未选中的复选框。然后我只能通过id更改的复选框。现在我通过所有id's进行单一更改。

回答

0

我认为您需要存储“原始状态”,如在您的所有复选框中添加一个rel属性。 在这个属性中,你只需编写一个隐藏字段的id存储你的复选框的原始状态。

<td class="cell"><input type="checkbox" id="shareRecorded" rel="shareRecordedState" /><span>Yes</span></td> 
<input type="hidden" id="shareRecordedState" value="1"/> 

最后你只需要检查原始状态。