2014-08-29 94 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