JQuery :包含以下单词之一
在这一行中,我尝试选择包含这些单词之一但不包含图像的 ,但它不起作用,基本上当我在页面上使用它时,该页是空白的。
$('#SubscribersManageList tr:contains("CIUDAD EVITA"), tr:contains("MORENO"), tr:contains("CORRIENTES"), tr:contains("LA MATANZA"), tr:contains("QUILMES"), tr:contains("LOMAS DE ZAMORA"), tr:contains("LANUS"), tr:contains("AVELLANEDA"), tr:contains("CORDOBA"), tr:contains("CAPITAL FEDERAL"), tr:contains("RAMOS MEJIA"):not(:has(img[src*="images/plus.gif"]))').css("background-color", "red").insertAfter("tr.Heading3:last");
如果该行包含以下任一单词,该怎么做,也许以更简单的方式?
您可以在这里测试:http://jsfiddle.net/cwar3/1/
On this line I'm trying to select <tr>
's that contain either one of these words but doesn't contain an image but it's not working, basically when I use it on the page, the page is blank.
$('#SubscribersManageList tr:contains("CIUDAD EVITA"), tr:contains("MORENO"), tr:contains("CORRIENTES"), tr:contains("LA MATANZA"), tr:contains("QUILMES"), tr:contains("LOMAS DE ZAMORA"), tr:contains("LANUS"), tr:contains("AVELLANEDA"), tr:contains("CORDOBA"), tr:contains("CAPITAL FEDERAL"), tr:contains("RAMOS MEJIA"):not(:has(img[src*="images/plus.gif"]))').css("background-color", "red").insertAfter("tr.Heading3:last");
How to do it, perhaps in a simplier way, if the line contains either one of the following words?
You can test here: http://jsfiddle.net/cwar3/1/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您要么必须将
#SubscribersManageList
与每个逗号分开,要么您可以像我下面所做的那样,并将其作为上下文传递一次。我可能会这样写(为了可读性而分成多行 - 你必须将它放回到一行才能使用它):根据你的评论,如果你想以特定的顺序将它们插入到 DOM 中,我建议这样做:
您可以在这里看到它的工作原理: http://jsfiddle.net/jfriend00/MzgbV/。
这将一次遍历一个数组,查找、设计样式,然后插入每个数组,并按数组顺序处理它们。它实际上向后遍历数组,因此最后插入的第一个结束。
You either have to have the
#SubscribersManageList
with every comma piece separately or you can do like I did below and pass it just once as the context. I would probably write it like this (broken up onto multiple lines only for readability here - you have to put it back on one line to use it):Per your comments, if you want to insert them back into the DOM in a specific order, I'd suggest this:
You can see it work here: http://jsfiddle.net/jfriend00/MzgbV/.
This will go through the array one at a time, finding, styling and then inserting each one and will process them in the array order. It actually goes through the array backwards so the last one inserted ends up first.
此过滤器变得如此复杂,您可能需要考虑使用
jQuery.fn.filter
功能:This filter is getting so complex that you might want to think about using the
jQuery.fn.filter
function:您可以在
.filter()
调用中使用正则表达式,而不是使用:contains
:所以它看起来像:
Instead of useing
:contains
, you can use a regular expression in a.filter()
call:So it would look like: