0

私がやろうとしていること: td をクリックして、同じクラスの div を表示します。

$(document).ready(function(){
   $("td").click(function () {
        var target = $(this).attr("class");
        $("div").show("slow");             //I want this div to have same class as target
   });
}); 
4

3 に答える 3

1
$("div." + target).show("slow");   

variable にクラスがありますtarget$('div.class')したがって、div を表示するにはドット構文を使用します。

于 2013-11-05T16:13:57.210 に答える
0

使用する

$("div." + target).show("slow");

あなたのコードは

$(document).ready(function () {
    $("td").click(function () {
        var target = $(this).attr("class");
        $("div." + target).show("slow");
    });
});
于 2013-11-05T16:14:06.720 に答える
0

試す

$(document).ready(function () {
    $("td").click(function () {
        var target = this.className;
        $("div." + target).show("slow");
    });
});
于 2013-11-05T16:14:19.700 に答える