【发布时间】:2012-06-05 17:35:16
【问题描述】:
我有很多类似这样的复选框的列表:
<ul>
<li><label class="highlight"><input type="checkbox" id="1" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="223" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="32" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="42" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="54" class="filteritem">Lorem Ipsum</label</li>
</ul>
<ul>
<li><label class="highlight"><input type="checkbox" id="43" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="343" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="342" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="53" class="filteritem">Lorem Ipsum</label</li>
<li><label class="highlight"><input type="checkbox" id="55" class="filteritem">Lorem Ipsum</label</li>
</ul>
每个复选框都有一个唯一的 ID
我想在检查时切换标签的背景颜色。
这是我得到的,但它不起作用:
jQuery:
$(".filteritem").click(function(){
$(this).toggleClass('highlight');
});
CSS:
.highlight {
//change something
}
【问题讨论】:
标签: jquery html css checkbox label