开发者

Passing a variable into :contains selector

wind开发者_开发技巧ow.something.updateStatus = function(theName) {
  $('#myTable').children('tr').remove(":contains('theName')");
};

Obviously the above does not work because it is looking for a string called "theName" in any in myTable.

What I'd like to do is pass in theName's Value to the contains.

How do I evaluate this expression?

Thanks.


This is untested, but should work:

window.something.updateStatus = function(theName) {
  $('#myTable').children('tr').remove(":contains('" + theName +"')");
};

Essentially it removes the variable theName from the string, but still quotes that value (once the variable's interpolated), which is why there's an opening, and closing, ' either side of the variable and + concatenation operators.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜