本文实例为大家分享了js实现筛选功能的具体代码,供大家参考,具体内容如下
功能
通过复选框对显示内容进行筛选,如,勾选后仅显示在线用户。
代码
js
※需 jQuery。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
function filter() {
var check =document.getElementById( 'checkbox' );
var members = $( '.member' );
var status = $( '.memberStatus' );
if (check.checked) {
members.each( function (i, member) {
if (status[i].innerText == 'Offline' ) {
member.style.display = 'none' ;
}
});
} else {
members.each( function (i, member) {
member.style.display = '' ;
});
}
}
|
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
< input type = "checkbox" name = "onlineOnly" tabindex = "0" id = "checkbox" onclick = "filter()" >
< span >Show online users only</ span >
< table >
< tr class = "member" >
< td >
UserA
</ td >
< td class = "memberStatus" >
Online
</ td >
</ tr >
< tr class = "member" >
< td >
UserB
</ td >
< td class = "memberStatus" >
Offline
</ td >
</ tr >
< tr class = "member" >
< td >
UserC
</ td >
< td class = "memberStatus" >
Online
</ td >
</ tr >
</ table >
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/wjianbo/article/details/109494953