如何找到其文本以特定字符串开头的li? [英] How to find li whose text starts with a particular string?
本文介绍了如何找到其文本以特定字符串开头的li?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个函数来获取顶部包含键
的< li>
标记在文本中的任何地方。
I have a function to get the <li>
tag at the top that contains the key
specified to it, anywhere in the text.
但是,我想要以钥匙开头的< li>
指定给它
这里是代码:
But I want to have the <li>
that starts with the key specified to it.
Here is the code:
function displaySearchResult(key){
var li=$('.listcontainer ul li:contains('+key+')');
li.parent().prepend(li);
}
所以如何获取< li> / code>标签,其文本以指定的
键开始
?
推荐答案
使用过滤器
。
var li = $('.listcontainer ul li').filter(function() { return $(this).text().indexOf(key) === 0; });
这篇关于如何找到其文本以特定字符串开头的li?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文