回答編集履歴
2
追記)radio / checkbox への対応
test
CHANGED
@@ -73,3 +73,35 @@
|
|
73
73
|
|
74
74
|
|
75
75
|
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
----
|
80
|
+
|
81
|
+
追記)radio / checkbox への対応
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
```javascript
|
86
|
+
|
87
|
+
// 3 キーバリューの entries を示す2次元配列を中継する
|
88
|
+
|
89
|
+
let keyval3 = [...inputs].reduce(e =>{
|
90
|
+
|
91
|
+
if( e.type.match(/radio|checkbox/) ? e.checked : true ) {
|
92
|
+
|
93
|
+
a.push([e.name, e.value]);
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
return a
|
98
|
+
|
99
|
+
}, []);
|
100
|
+
|
101
|
+
let sea3 = new URLSearchParams(keyval2);
|
102
|
+
|
103
|
+
let href3 = "?" + sea2.toString();
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
```
|
1
追記
test
CHANGED
@@ -13,6 +13,14 @@
|
|
13
13
|
let params2 = new URLSearchParams([["a","AA"],["b","BB"]]);
|
14
14
|
|
15
15
|
console.log( params2.toString() );// "a=AA&b=BB"
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
// 追記:input[type=checkbox] など 複数選択可能なフォーム情報を扱う場合
|
20
|
+
|
21
|
+
var params3 = new URLSearchParams([["a","AA"],["b","BB"],["b","BB2"]]);
|
22
|
+
|
23
|
+
console.log( params3.toString() );// "a=AA&b=BB&b=BB2"
|
16
24
|
|
17
25
|
```
|
18
26
|
|