获取从默认设置更改的所有复选框的 id

Get the id of all the checkbox which is altered from the default setting

本文关键字:复选框 id 默认 设置 获取      更新时间:2023-09-26

我有以下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进行单一更改。

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

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

最后,您只需要检查原始状态即可。