JS filters-ul li简单过滤
2021-05-17 19:27
标签:lower .com indexof ott lte ice href font jquery 功能要求:在input中输入字母,显示ul li中匹配的元素,隐藏不匹配的 JS-自己编写的匹配函数 JS-使用Javascript的indexOf函数 JQuery版 JS filters-ul li简单过滤 标签:lower .com indexof ott lte ice href font jquery 原文地址:http://www.cnblogs.com/coding-swallow/p/7742277.html 1 DOCTYPE html>
2 html>
3 head>
4 meta charset="utf-8">
5 meta name="viewport" content="width=device-width">
6 title>JS Bintitle>
7 script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">script>
8 head>
9 body>
10 input type="text" id="search-input" placeholder="Search for names..">
11 ul id="name-list">
12 li>a href="#">Adelea>li>
13 li>a href="#">Adeaba>li>
14 li>a href="#">Adqlla>li>
15 li>a href="#">Adella>li>
16 li>a href="#">Agnesa>li>
17
18 li>a href="#">Billya>li>
19 li>a href="#">Boba>li>
20
21 li>a href="#">Calvina>li>
22 li>a href="#">Christinaa>li>
23 li>a href="#">Cindya>li>
24 ul>
25 body>
26 html>
#search-input{
width:200px;
height:25px;
font-size:16px;
border-radius:5px;
outline:none;
border:none;
border:1px solid orange;
padding-left:10px;
}
ul{
list-style:none;
padding:0;
margin:0;
width:200px;
}
li{
border-bottom:1px solid #ccc;
padding:5px 10px;
}
a{
text-decoration:none;
color:#333;
}
1 var input=document.getElementById(‘search-input‘);
2 var lis=document.getElementsByTagName(‘li‘);
3 input.onkeyup=function(){
4 var input_str=input.value;
5 for(var i=0;i
1 var input=document.getElementById(‘search-input‘);
2 var lis=document.getElementsByTagName(‘li‘);
3 input.onkeyup=function(){
4 var input_str=input.value;
5 for(var i=0;i
1 $(function(){
2 $(‘#search-input‘).on(‘keyup‘,function(){
3 var $str=$(‘#search-input‘).val();
4 $(‘ul li‘).each(function(){
5 if(!$(this).text().toUpperCase().indexOf($str.toUpperCase())){
6 $(this).show();
7 }
8 else{
9 $(this).hide();
10 }
11 });
12 });
13 })
文章标题:JS filters-ul li简单过滤
文章链接:http://soscw.com/index.php/essay/86845.html