小编jac*_*ode的帖子

试图在jQuery中将元素ID转换为类选择器

这是我的jsfiddle:

http://jsfiddle.net/fk434/

代码:

$('.theHider').click(function () {
    $("'." + $(this).id + "'").hide();
});
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

我不明白为什么这不起作用.

至于文件准备等等,当它阻止jsfiddle工作时我把它拿出来了.

html javascript jquery dom

2
推荐指数
2
解决办法
226
查看次数

标签 统计

dom ×1

html ×1

javascript ×1

jquery ×1