仅考虑jquery中的已更改复选框

Pra*_*ash 2 checkbox each jquery

我在页面上有一些复选框(一些已经通过html检查属性检查过)和一个提交按钮.我想使用jquery运行一个使用$ .each()循环的函数,以便在选中复选框时执行该函数,但前提是它尚未选中.此外,我想为每个未选中的复选框执行一个功能,但前提是它已经被选中.

请帮忙

Mat*_*ert 5

一种方法是使用.data()存储复选框的原始值.

$(document).ready(function(){
     $("input[type='checkbox']").each(function(){
        $(this).data("originalValue", $(this).is(":checked"));
    })
});;

$("#ok").click(function(){
    $("input[type='checkbox']").each(function(){
       var edited = $(this).data("originalValue") !== $(this).is(":checked");
       if (edited)
       {
           var checkboxLabel = $(this).next("label");
           alert("edited: " + checkboxLabel.text());
       }
    });
});
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/8g3uz/3/

检查用户交互而不是更改的原始解决方案:http://jsfiddle.net/8g3uz/1/