回答編集履歴

3

調整

2019/01/15 07:17

投稿

yambejp
yambejp

スコア114839

test CHANGED
@@ -12,13 +12,15 @@
12
12
 
13
13
  # sample
14
14
 
15
+ とりあえず冗長に書いてみました。
16
+
15
17
  ```javascript
16
18
 
17
19
  <script>
18
20
 
19
21
  $(function(){
20
22
 
21
- $('#button').on("click",function(){
23
+ $('#button1').on("click",function(){
22
24
 
23
25
  var re = new RegExp($('#search').val().trim().replace(/ +/,"|"));
24
26
 
@@ -36,6 +38,34 @@
36
38
 
37
39
  $('#button2').on("click",function(){
38
40
 
41
+ $('#result tbody tr').each(function(){
42
+
43
+ var tr=$(this);
44
+
45
+ var re=$('#search').val().trim().split(/ +/);
46
+
47
+ var flg=re.map(function(x){
48
+
49
+ return tr.has($('td').filter(function(){
50
+
51
+ return $(this).text().match(new RegExp(x));
52
+
53
+ })).get();
54
+
55
+ }).filter(function(x){
56
+
57
+ return x.length>0;
58
+
59
+ }).length==re.length;
60
+
61
+ tr.toggle(flg);
62
+
63
+ });
64
+
65
+ });
66
+
67
+ $('#button3').on("click",function(){
68
+
39
69
  $('#result tr').show();
40
70
 
41
71
  });
@@ -46,9 +76,11 @@
46
76
 
47
77
  <input type="text" id="search" value=" a b ">
48
78
 
49
- <input type="button" value="絞り込む" id="button">
79
+ <input type="button" value="or検索" id="button1">
50
80
 
81
+ <input type="button" value="and検索" id="button2">
82
+
51
- <input type="button" value="すべて表示" id="button2">
83
+ <input type="button" value="すべて表示" id="button3">
52
84
 
53
85
 
54
86
 

2

chousei

2019/01/15 07:17

投稿

yambejp
yambejp

スコア114839

test CHANGED
File without changes

1

sample

2019/01/15 07:16

投稿

yambejp
yambejp

スコア114839

test CHANGED
@@ -7,3 +7,97 @@
7
7
  とすればスペース区切りで書かれたものはor検索できます。
8
8
 
9
9
  (ただし「|」という文字はそのままでは検索できない)
10
+
11
+
12
+
13
+ # sample
14
+
15
+ ```javascript
16
+
17
+ <script>
18
+
19
+ $(function(){
20
+
21
+ $('#button').on("click",function(){
22
+
23
+ var re = new RegExp($('#search').val().trim().replace(/ +/,"|"));
24
+
25
+ $('#result tbody tr').each(function(){
26
+
27
+ $(this).toggle($(this).find('td').filter(function(){
28
+
29
+ return $(this).text().match(re)?true:false;
30
+
31
+ }).length>0);
32
+
33
+ });
34
+
35
+ });
36
+
37
+ $('#button2').on("click",function(){
38
+
39
+ $('#result tr').show();
40
+
41
+ });
42
+
43
+ });
44
+
45
+ </script>
46
+
47
+ <input type="text" id="search" value=" a b ">
48
+
49
+ <input type="button" value="絞り込む" id="button">
50
+
51
+ <input type="button" value="すべて表示" id="button2">
52
+
53
+
54
+
55
+ <table id="result">
56
+
57
+ <tbody>
58
+
59
+ <tr>
60
+
61
+ <td>1</td>
62
+
63
+ <td>aaa</td>
64
+
65
+ <td>bbb</td>
66
+
67
+ </tr>
68
+
69
+ <tr>
70
+
71
+ <td>2</td>
72
+
73
+ <td>aaa</td>
74
+
75
+ <td>---</td>
76
+
77
+ </tr>
78
+
79
+ <tr>
80
+
81
+ <td>3</td>
82
+
83
+ <td>bbb</td>
84
+
85
+ <td>---</td>
86
+
87
+ </tr>
88
+
89
+ <tr>
90
+
91
+ <td>4</td>
92
+
93
+ <td>---</td>
94
+
95
+ <td>---</td>
96
+
97
+ </tr>
98
+
99
+ </tbody>
100
+
101
+ </table>
102
+
103
+ ```