我有项目列表和一个搜索框。如果搜索词输入到搜索框中,匹配的文本应该在列表中以粗体字显示,而不考虑大小写(不区分大小写)。 我做了一些水平,但后来我不知道该怎么做,因为我是新来的jQuery。如何高亮jquery中匹配项的文本?
<html>
<head>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".SearchElement").keyup(function(){
keyword = $(".SearchElement").val();
if(keyword.length>=3){
var content = $(".wrapperbox ul li").text();
test = content.match(/keyword/gi)
if(test){
//alert(test);
}
}
});
});
</script>
</head>
<body>
<form action="">
<label>SearchTerm:</label> <input type="text"
name="SearchBox" value="" class="SearchElement" />
</form>
<div class="wrapperbox">
<ul>
<li>TestString</li>
<li>testString</li>
<li>Kanigiri</li>
<li>KANIGIRI</li>
</ul>
</div>
</body>
</html>
我该怎么做,任何帮助将大大appriciated。谢谢
看看我的回答[此问题](http://stackoverflow.com/questions/12505602/slow-highlighting -in-火狐/ 12505656#12505656)。 – elclanrs
请提供更好的标题,以便将来的搜索者能够找到它。 –