2011-05-13 93 views
0

嗨H与一些代码,带回一个链接的类名如何将#添加到VAR

var activeTab = $(this).attr("class"); 

因此,可以说上述带回“一”

我的价值需要提前

var activeTab = $(this).attr("class"); 
      $(activeTab).stop(true, false).animate({ height: "200px" }); 

由于追加这是#one为下面的代码

回答

0

您可以使用+操作字符串连接这样的:

 
$('#' + activeTab) 
0
var activeTab = $(this).attr("class"); 
activeTab = '#' + activeTab; 
$(activeTab).stop(true, false).animate({ height: "200px" }); 
+0

为什么要添加第二行? – locrizak 2011-05-13 15:44:13

+0

我在回答中明确表示。我同意,第二个例子在实际代码中并不一定需要。 – 2011-05-13 15:46:31

1
在Javascript

很简单:

var_name = '#' + var_name; 
1

您可以使用+字符串连接:

$('#' + activeTab) 
0

$( '#' + activeTab)....

?!

var activeTab = $(this).attr("class"); 
$("#" + activeTab).stop(true, false).animate({ height: "200px" }); 
0
var activeTab = "#" + $(this).attr("class"); 
$(activeTab).stop(true, false).animate({ height: "200px" });

我认为这是你想要做什么。