Sunday, 15 July 2012

jquery - Trouble combining checkboxes with this find function -


I'm having this find function having trouble working with the checkbox Was also not able to select the checkbox and was therefore asked to remove the statement return; I'm not sure whether that is the reason or not, but the statement if (attrcolor == 'all') {...} is no longer working.

How can I modify this function so it will work with the checkbox, in which all have to show, if it is selected?

I have posted a bella with a simple example of the function:

  $ (document) .ready (function () {var selected = []; $ ( '# Attributes - $ (this); if ($ this.parent ()) ifClass ("active") $ $ This.parent (). RemoveClass ("active"); selected splice (selected.indexOf (atrolar) 1);} and {$ this.parent (). AddClass ("active"); Selected push (atrrolor);} if (atrolar == 'all') {$ ('#'). ('*') Find (show);} and {$ ("#content"). ") (), ($ ['Data-color * =' '+ item +'"] '). (Show,);}); } // It was removed to allow checkboxes to accept input / return incorrectly; }); });    

Target only checkboxes, and not all elements like Asterix selector, and checkboxes Use "change" event for.

Then get all the Li elements in the variable lis , and hide them all at the same time.

> Check all checked checkboxes $ Map . Mark an array with

isAll , to see that the "all" value is the array that checkbox is checked, if it is, Or if any check boxes are not checked, then the length is zero, show all li , otherwise the colors will be redundant with the code $. Every , and look for any of the matching colors.

  $ (document) .ready (function () {$ ('# attributes-color input [type = "checkbox"]') .on ('change', function () {var Lis = $ ('# content li'). Hide (), check = $ .map ($ ('# attributes-color input [type = "checkbox"]'), function (L, I) {if (el. Checked) $ (el) .data ('c olor');}), isAll = $ .inArray ('all', check)! = -1; If (check.length & isAll) {$ .each (Check, function (i, color) {lis.filter (function () {return $ (this). Data ('color'). IndexOf (color)! = -1}). Show ();});} Else {lis.show ();}});});   



No comments:

Post a Comment