2014-08-29 91 views
0

這工作:傳遞一個變量jQuery選擇

function rowColors(){ 
    $("table#remotes th").css("background-color", "#202020"); 
    $("table#remotes tr").css("background-color", "#484848"); 
    $("table#remotes tr:visible:odd").css("background-color", "#333333"); 
} 

我怎樣才能讓一個變量表ID這項工作?這是行不通的:

function rowColors(tblid){ 
    $("table#"+tblid+" th").css("background-color", "#202020"); 
    $("table#"+tblid+" tr").css("background-color", "#484848"); 
    $("table#"+tblid+" tr:visible:odd").css("background-color", "#333333"); 
} 

rowColors(remotes);

回答

6

也許是因爲remotes是一個變量,而不是一個字符串

rowColors('remotes'); 
+0

是啊,這是值得一提此無關的jQuery明確。 – naomik 2014-08-29 19:37:58