javascript - remove value from the list -
I have a list of checkboxes When I click on each checkbox I am adding value to the hidden variable. But the question is whether I want to remove the value from the list when I uncheck the checkbox. How this slice cab is done
There is a hidden form variable
and jquery
$ (". MyCheckboxClass"). Change (function () {var output = 0; $ (". MyCheckboxClass") (Outlook = "," + $ (this) .val ();} and {output = $ .grep (output, function (value) { Return value! = $ (This) .val ();})}} $ ("# idlist"). Val (output);});});
Something like this: (demo)
We use it To store the object, add and remove the vals objects as check / uncheck. var vals = {}; $ ('Input [type = checkbox]'). Click (function () {var that = $ (this); if (that.is (': checked')) {console.log (this.name); vals [this.name] = "in your object"; } And {delete vals [this.name];} console.log (vals);});
Comments
Post a Comment