我正在尝试查找具有title属性的元素,这些元素的值与我提供的不区分大小写的字符串匹配。即。不管它们是否大小写都匹配。
当我尝试以下操作时,它会起作用:
$(".head[title*='premier' i]").length
但是当我想与更多过滤器结合使用时,会出现错误:
$(".itemSport").eq(0).find(".groupMenu:contains(England)")
.find(".head[title*='premier' i]").length
在组合其他前面的过滤器时,哪种方法是获取标题属性与提供的字符串匹配的元素的最佳方法?
编辑:链接到我正在查询的页面
https://web.betin.co.ke/Sport/Groups.aspx?IDSport=20&Antepost=0
我想在第一个足球按钮下找到包含“ Premier”的元素(有时,大小写更改,这就是为什么我需要查询不区分大小写的原因):
<div class="head" ng-click="openEvent()" title="Premier League">
<span class="nameEvent ng-binding" ng-bind="itemEvent.Evento">Premier League</span>
<span class="eventCount ng-binding" ng-bind="itemEvent.NumSottoeventi">20</span>
</div>
答案 0 :(得分:2)
不确定为什么您的查询不起作用。可能是使用.find
方法的JQuery错误。
要解决此问题,请使用此
:$(".itemSport")
.eq(0)
.find(".groupMenu:contains(England)")
.find( $(".head[title*='premier' i]") )
.length
基本上避免在.find
方法中使用CSS选择器,而是向其传递元素列表。