0

我有以下内容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的单一变化。

4

1 回答 1

0

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

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

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

于 2012-07-06T10:33:03.917 回答