回答編集履歴

2

調整

2017/10/26 02:26

投稿

yambejp
yambejp

スコア114845

test CHANGED
@@ -42,15 +42,17 @@
42
42
 
43
43
  var v=$(this).val();
44
44
 
45
- $('#'+$(this).attr('list')+" option").prop('disabled',false).filter(function(){
45
+ $('#'+$(this).attr('list')+" option").prop('disabled',function(){
46
46
 
47
- return !$(this).val().match(new RegExp("^"+v))
47
+ return !$(this).val().match(new RegExp("^"+v));
48
48
 
49
- }).prop('disabled',true);
49
+ });
50
50
 
51
51
  });
52
52
 
53
53
  });
54
+
55
+
54
56
 
55
57
  ```
56
58
 

1

追記

2017/10/26 02:26

投稿

yambejp
yambejp

スコア114845

test CHANGED
@@ -53,3 +53,35 @@
53
53
  });
54
54
 
55
55
  ```
56
+
57
+
58
+
59
+ # 追記
60
+
61
+ 念の為javascript版
62
+
63
+
64
+
65
+ ```javascript
66
+
67
+ document.addEventListener('input',function(e){
68
+
69
+ var t=e.target;
70
+
71
+ if(t.nodeName=="INPUT" && t.type=="search"){
72
+
73
+ var v=t.value;
74
+
75
+ var l=t.getAttribute('list');
76
+
77
+ Array.prototype.map.call(document.querySelectorAll('#'+l+' option'),function(i){
78
+
79
+ i.disabled=!i.value.match(new RegExp("^"+v));
80
+
81
+ });
82
+
83
+ }
84
+
85
+ });
86
+
87
+ ```