質問編集履歴
4
説明とhtmlタグを追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
ページ内の一覧から、キーワード検索できるようにInputboxを設置しております。
|
3
3
|
現在は、1つのキーワードで検索できます↓が、複数のキーワードで検索できるようにしたいのですが、どうなおしたらいいのか、わかりません。
|
4
4
|
jQueryは素人です。
|
5
|
+
例ですが、inputboxに「1 a」で検索をかけると1行目のみ表示したいのです。
|
6
|
+
今の記述だと1つのワードしか検索かけられません。
|
7
|
+
アドバイスいただけると助かります!
|
5
8
|
|
6
9
|
```jQuery
|
7
10
|
jQuery$(function() {
|
@@ -28,4 +31,11 @@
|
|
28
31
|
<input type="text" id="search">
|
29
32
|
<input type="button" value="絞り込む" id="button">
|
30
33
|
<input type="button" value="すべて表示" id="button2">
|
34
|
+
|
35
|
+
<table id="result"><tbody>
|
36
|
+
<tr><td>123</td><td>abc</td></tr>
|
37
|
+
<tr><td>456</td><td>ddd</td></tr>
|
38
|
+
<tr><td>456</td><td>aaa</td></tr>
|
39
|
+
<tr><td>123</td><td>ccc</td></tr>
|
40
|
+
</tbody></table>
|
31
41
|
```
|
3
修正しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,24 +4,25 @@
|
|
4
4
|
jQueryは素人です。
|
5
5
|
|
6
6
|
```jQuery
|
7
|
-
$(function()
|
7
|
+
jQuery$(function() {
|
8
|
-
|
8
|
+
$('#button').on("click", function() {
|
9
|
-
|
9
|
+
var re = new RegExp($('#search').val());
|
10
|
-
|
10
|
+
$('#result tbody tr').each(function() {
|
11
|
-
|
11
|
+
var tr = $(this);
|
12
|
-
|
12
|
+
tr.hide();
|
13
|
-
|
13
|
+
$('td', this).each(function() {
|
14
|
-
|
14
|
+
var txt = $(this).html();
|
15
|
-
|
15
|
+
if (txt.match(re) != null) {
|
16
|
-
|
16
|
+
tr.show();
|
17
|
-
|
17
|
+
}
|
18
|
-
|
18
|
+
});
|
19
|
-
|
19
|
+
});
|
20
|
-
|
20
|
+
});
|
21
|
-
|
21
|
+
$('#button2').on("click", function() {
|
22
|
-
|
22
|
+
$('#result tr').show();
|
23
|
-
|
23
|
+
});
|
24
|
-
|
24
|
+
});
|
25
|
+
|
25
26
|
```
|
26
27
|
```html
|
27
28
|
<input type="text" id="search">
|
2
functionがきれていたので修正しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
jQueryは素人です。
|
5
5
|
|
6
6
|
```jQuery
|
7
|
-
$(
|
7
|
+
$(function(){
|
8
8
|
$('#button').on("click",function(){
|
9
9
|
var re = new RegExp($('#search').val());
|
10
10
|
$('#result tbody tr').each(function(){
|
1
インデントを修正してみましたが、すみません。素人なので醜いかもしれません。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,31 +1,30 @@
|
|
1
1
|
社内サーバー(Webサーバーではない)にHTMLを作成しています。
|
2
2
|
ページ内の一覧から、キーワード検索できるようにInputboxを設置しております。
|
3
3
|
現在は、1つのキーワードで検索できます↓が、複数のキーワードで検索できるようにしたいのですが、どうなおしたらいいのか、わかりません。
|
4
|
-
jjj
|
5
|
-
|
4
|
+
jQueryは素人です。
|
5
|
+
|
6
|
-
```
|
6
|
+
```jQuery
|
7
7
|
$(func tion(){
|
8
|
-
|
8
|
+
$('#button').on("click",function(){
|
9
|
-
|
9
|
+
var re = new RegExp($('#search').val());
|
10
|
-
|
10
|
+
$('#result tbody tr').each(function(){
|
11
|
-
|
11
|
+
var tr = $(this);
|
12
|
-
|
12
|
+
tr.hide();
|
13
|
-
|
13
|
+
$('td', this).each(function(){
|
14
|
-
|
14
|
+
var txt = $(this).html();
|
15
|
-
|
15
|
+
if(txt.match(re) != null){
|
16
|
-
|
16
|
+
tr.show();
|
17
|
-
|
17
|
+
}
|
18
|
-
|
18
|
+
});
|
19
|
-
|
19
|
+
});
|
20
|
-
|
20
|
+
});
|
21
21
|
$('#button2').on("click",function(){
|
22
|
-
|
22
|
+
$('#result tr').show();
|
23
|
+
});
|
23
24
|
});
|
24
|
-
});
|
25
|
-
|
26
25
|
```
|
27
|
-
html
|
26
|
+
```html
|
28
|
-
|
27
|
+
<input type="text" id="search">
|
29
|
-
<input type="
|
28
|
+
<input type="button" value="絞り込む" id="button">
|
30
|
-
|
29
|
+
<input type="button" value="すべて表示" id="button2">
|
31
30
|
```
|