jQuery选择器,其中文本=一些值 [英] jQuery selector where text = some value

查看:89
本文介绍了jQuery选择器,其中文本=一些值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象(在本例中为js-kit中的一个评级对象),如果评级值为未评级",我想使其不可见.我在获取正确的jQuery选择器来执行此操作时遇到了麻烦.

I have an object (in this case a rating object from js-kit) that I want to make invisible if the rating value is 'unrated'. I'm having trouble with getting the right jQuery selector to do this.

即使下面的代码看起来应该可以工作,也不能.

Even though the code below seems like it should work, it does not.

$(".js-rating-labelText:contains('unrated')").css("visibility", "hidden");  

.js-rating-labelText是在文本上设置的类.

.js-rating-labelText is a class that's set on the text.

推荐答案

还有其他方法可以根据文本内容选择元素吗?

Is there another way to select an element based on the text contents?

尝试一下:

$('.js-rating-labelText').filter(function(){
  return (/unrated/i).test($(this).text())
}).css('visibility', 'hidden');

这篇关于jQuery选择器,其中文本=一些值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆