这是我的jsfiddle:
编码:
$('.theHider').click(function () {
$("'." + $(this).id + "'").hide();
});
的HTML:
<div class="cola">This will be cola</div>
<div class="cola">This will be cola</div>
<div class="birch">This will be birch</div>
<div class="cola">This will be cola</div>
<div class="cola">This will be cola</div>
<div class="orange">This will be orange</div>
<div class="birch">This will be birch</div>
<div id="cola" class="theHider">This will hide cola</div>
<div id="birch" class="theHider">This will hide birch</div>
<div id="orange" class="theHider">This will hide orange</div>
我不明白为什么这不起作用。
至于准备好文档等,我在阻止 jsfiddle 工作时将其取出。