我做了这个小提琴:http: //jsfiddle.net/GMH6q/2/
HTML:
<div class="feature" id="about">about</div>
<div class="feature" id="services">services</div>
<div class="feature" id="products">products</div>
<label>About</label><input type="checkbox" data-id="about" />
<label>Services</label><input type="checkbox" data-id="services" />
<label>Products</label><input type="checkbox" data-id="products" />
JavaScript:
$(document).ready(function(){
var priority = {'about':1, 'services':2, 'products':3};
$('input[type="checkbox"]').change(function(){
var el = $(this).attr('data-id');
if($(this).is(':checked')){
$('.feature').hide();
$('.feature#' + el).show();
} else {
$('.feature#' + el).hide();
}
});
});
如果about
打开,则单击任何其他复选框将没有任何效果。
同样,如果services
是 on,则 put products
on 不会有任何效果,但 put about
in 只会显示about
。
如果一切都打开,那么about
只是显示。
如果全部关闭,则没有任何显示。
优先级数组需要以某种方式集成,但我不知道如何。如果有人可以帮助我解决一些逻辑并集成数组,那就太好了!