jQuery:逐文本查找元素有谁能告诉我是否有可能根据其内容而不是通过ID或班级,等级?我试图找到没有不同类或id的元素。(然后我需要找到该元素的父元素。)
3 回答
不负相思意
TA贡献1777条经验 获得超10个赞
匹配的文本可以直接出现在所选元素中、在该元素的任何子元素中,也可以出现在该元素的组合中。
:contains() 选择器
function findElementByText(text) {
var jSpot = $("b:contains(" + text + ")")
.filter(function() { return $(this).children().length === 0;})
.parent(); // because you asked the parent of that element
return jSpot;}
慕侠2389804
TA贡献1719条经验 获得超6个赞
var text = "text";var search = $( "ul li label" ).filter( function (){
return $( this ).text().toLowerCase().indexOf( text.toLowerCase() ) >= 0;}).first();
// Returns the first element that matches the text. You can return the last one with .last()- 3 回答
- 0 关注
- 578 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消
