質問編集履歴
3
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,7 +66,7 @@
|
|
66
66
|
|
67
67
|
[id, val] = q.split('=');
|
68
68
|
|
69
|
-
if($(`#${id}`).attr('type') == checkbox)
|
69
|
+
if($(`#${id}`).attr('type') == 'checkbox')
|
70
70
|
|
71
71
|
$(`#${id}`).prop('checked', val == 'true');
|
72
72
|
|
2
書式の改善
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[jQuery] 特定の要素の子孫に存在するフォームの状態を記憶したい
|
1
|
+
a[jQuery] 特定の要素の子孫に存在するフォームの状態を記憶したい
|
test
CHANGED
@@ -62,7 +62,7 @@
|
|
62
62
|
|
63
63
|
if(params) {
|
64
64
|
|
65
|
-
|
65
|
+
params.split('&').map(q => {
|
66
66
|
|
67
67
|
[id, val] = q.split('=');
|
68
68
|
|
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,45 +14,81 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
|
17
|
+
```js
|
18
18
|
|
19
|
-
|
19
|
+
<html>
|
20
20
|
|
21
|
-
|
21
|
+
<head>
|
22
22
|
|
23
|
-
|
23
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
24
24
|
|
25
|
-
|
25
|
+
</head>
|
26
26
|
|
27
|
-
|
27
|
+
<body>
|
28
28
|
|
29
|
+
<input type="text" name="n1" id="i1">
|
30
|
+
|
31
|
+
<input type="number" name="n2" id="i2">
|
32
|
+
|
29
|
-
|
33
|
+
<select name="n3" id="i3"></select>
|
34
|
+
|
35
|
+
<select multiple name="n4" id="i4"></select>
|
36
|
+
|
37
|
+
<input type="checkbox" checked name="n5" id="i5">
|
38
|
+
|
39
|
+
<input type="checkbox" name="n5" id="i5">
|
30
40
|
|
31
41
|
|
32
42
|
|
43
|
+
<script>
|
33
44
|
|
45
|
+
const formStateString = (base) => {
|
34
46
|
|
35
|
-
|
47
|
+
let query = '';
|
36
48
|
|
37
|
-
i
|
49
|
+
console.log(base.find('select:enabled, input[type="number"]:enabled, input[type="text"]:enabled'));
|
38
50
|
|
39
|
-
|
51
|
+
base.find('select:enabled, input[type="number"]:enabled, input[type="text"]:enabled').map(e => query = `${query? `${query}&` : ''}${$(e).attr('id')}=${$(e).val()}`);
|
40
52
|
|
41
|
-
|
53
|
+
base.find('input[type="checkbox"]').map(e => query = `${query? `${query}&` : ''}${$(e).attr('id')}=${$(e).prop('checked')}`);
|
42
54
|
|
43
|
-
if($(`#${id}`).attr('type') == checkbox)
|
44
|
-
|
45
|
-
$(`#${id}`).prop('checked', val == 'true');
|
46
|
-
|
47
|
-
else
|
48
|
-
|
49
|
-
|
55
|
+
return query;
|
50
|
-
|
51
|
-
});
|
52
56
|
|
53
57
|
}
|
54
58
|
|
59
|
+
|
60
|
+
|
61
|
+
const setParams = (params) => {
|
62
|
+
|
63
|
+
if(params) {
|
64
|
+
|
65
|
+
q.split('&').map(q => {
|
66
|
+
|
67
|
+
[id, val] = q.split('=');
|
68
|
+
|
69
|
+
if($(`#${id}`).attr('type') == checkbox)
|
70
|
+
|
71
|
+
$(`#${id}`).prop('checked', val == 'true');
|
72
|
+
|
73
|
+
else
|
74
|
+
|
75
|
+
$(`#${id}`).val(val);
|
76
|
+
|
77
|
+
});
|
78
|
+
|
79
|
+
}
|
80
|
+
|
55
|
-
};
|
81
|
+
};
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
formStateString($('body'));
|
86
|
+
|
87
|
+
</script>
|
88
|
+
|
89
|
+
</body>
|
90
|
+
|
91
|
+
</html>
|
56
92
|
|
57
93
|
```
|
58
94
|
|