I have an application which provides a list of filters.
Each filter has an "include" and "exclude" button, for example:
<input type="button" name="include_337" value="+">
<input type="button" name="exclude_337" value="-"> Filter 1
<input type="button" name="include_856" value="+">
<input type="button" name="exclude_856" value="-"> Filter 2
So this renders a +
(for "include") and -
(for "exclude") button with the filter name listed beside it. The name
attribute of the buttons shows whether it is a button to include (include_
) or exclude (exclude_
) the filter, followed by an ID number that comes from a database.
When any of the buttons are clicked I place an active
class on the button. I recently asked about how to toggle those buttons: Toggle active class on a button but maintain state of other buttons
However, I have a separate issue. If I click, for example, -
on Filter 1 it will add the active
class:
<input type="button" name="include_337" value="+">
<input type="button" name="exclude_337" class="active" value="-"> Filter 1
It should not be possible to have the active
class on both the include and exclude button. However, I'm not sure how to do this. At the moment, it's possible to click the +
on Filter 1 and both will get the active
class:
<input type="button" name="include_337" class="active" value="+">
<input type="button" name="exclude_337" class="active" value="-"> Filter 1
What I want is effectively like radio buttons, where it's only possible to have either +
or -
active at any one time for a specific filter. However these must be button elements, not radio buttons, so I don't want to change the type
attribute.
I've had a look at jQuery: Uncheck other checkbox on one checked but this is slightly different as it uses radio buttons and also unchecks all other checkboxes. In this case I want it to apply to groups of filters - i.e. changing Filter 1 should not affect Filter 2, etc. Is this possible?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…