2011-05-13 90 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" });

我認爲這是你想要做什麼。