回答編集履歴

1

修正

2019/01/18 01:26

投稿

yambejp
yambejp

スコア114876

test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  $('#button1').on("click",function(){
12
12
 
13
- var re = new RegExp($('#search').val().trim().replace(/ +/,"|"));
13
+ var re = new RegExp($('#search').val().trim().replace(/ +/g,"|"));
14
14
 
15
15
  $('#result tbody tr').each(function(){
16
16
 
@@ -58,33 +58,33 @@
58
58
 
59
59
  });
60
60
 
61
- $('#button4').on("click",function(){
61
+ $('#check1').on("change",function(){
62
62
 
63
- if($(this).data('on')!="1"){
63
+ $('#result td').each(function(){
64
64
 
65
+ $(this).text($(this).text());
66
+
67
+ });
68
+
65
- $(this).data('on',"1");
69
+ if($(this).prop('checked')){
66
70
 
67
71
  $('#result td').each(function(){
68
72
 
69
- var re = new RegExp("("+$('#search').val().trim().replace(/ +/,"|")+")+",'g');
73
+ var re = new RegExp("("+$('#search').val().trim().replace(/ +/g,"|")+")+",'g');
70
74
 
71
75
  $(this).html($(this).html().replace(re,'<span style="display:inline-block;background-color:yellow">$&</span>'));
72
-
73
- });
74
-
75
- }else{
76
-
77
- $(this).data('on',null);
78
-
79
- $('#result td').each(function(){
80
-
81
- $(this).text($(this).text());
82
76
 
83
77
  });
84
78
 
85
79
  }
86
80
 
87
81
  });
82
+
83
+ $('#search').on('keyup',function(){
84
+
85
+ $('#check1').trigger('change');
86
+
87
+ });
88
88
 
89
89
  });
90
90
 
@@ -98,7 +98,7 @@
98
98
 
99
99
  <input type="button" value="すべて表示" id="button3">
100
100
 
101
- <input type="button" value="ハイライト" id="button4">
101
+ <label><input type="checkbox" id="check1">ハイライト</label>
102
102
 
103
103
 
104
104