質問編集履歴
4
ソース修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,8 +11,6 @@
|
|
11
11
|
```
|
12
12
|
|
13
13
|
<input id="first_zip" type="text" name="1人目の郵便番号">
|
14
|
-
|
15
|
-
|
16
14
|
|
17
15
|
<select id="mode">
|
18
16
|
|
@@ -34,13 +32,21 @@
|
|
34
32
|
|
35
33
|
```
|
36
34
|
|
37
|
-
let
|
35
|
+
let modeList = document.getElementById('mode');
|
38
36
|
|
39
|
-
if(! sample.value) {
|
40
37
|
|
41
|
-
sample.value = document.getElementbyId('first_zip').value
|
42
38
|
|
39
|
+
modeList.addEventListener('change', function(e){
|
40
|
+
|
41
|
+
let sample = document.getElementById('second_zip')
|
42
|
+
|
43
|
+
if(! sample.value) {
|
44
|
+
|
45
|
+
sample.value = document.getElementById('first_zip').value
|
46
|
+
|
43
|
-
}
|
47
|
+
}
|
48
|
+
|
49
|
+
});
|
44
50
|
|
45
51
|
```
|
46
52
|
|
@@ -50,9 +56,9 @@
|
|
50
56
|
|
51
57
|
```
|
52
58
|
|
53
|
-
if(! document.getElementbyId('s
|
59
|
+
if(! document.getElementbyId('second_zip').value) {
|
54
60
|
|
55
|
-
document.getElementbyId('s
|
61
|
+
document.getElementbyId('second_zip').value = document.getElementbyId('first_zip').value
|
56
62
|
|
57
63
|
}
|
58
64
|
|
3
サンプルコード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,11 +34,11 @@
|
|
34
34
|
|
35
35
|
```
|
36
36
|
|
37
|
-
let sample = document.getElementbyId('s
|
37
|
+
let sample = document.getElementbyId('second_zip')
|
38
38
|
|
39
39
|
if(! sample.value) {
|
40
40
|
|
41
|
-
sample.value = '
|
41
|
+
sample.value = document.getElementbyId('first_zip').value
|
42
42
|
|
43
43
|
}
|
44
44
|
|
@@ -52,7 +52,7 @@
|
|
52
52
|
|
53
53
|
if(! document.getElementbyId('sample').value) {
|
54
54
|
|
55
|
-
document.getElementbyId('sample').value = '
|
55
|
+
document.getElementbyId('sample').value = document.getElementbyId('first_zip').value
|
56
56
|
|
57
57
|
}
|
58
58
|
|
2
目的追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,21 +2,35 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
例えば、下記の様な
|
5
|
+
例えば、下記の様なHTMLがあるとします。
|
6
|
+
|
7
|
+
同じ要素が複数ある場合、最初の要素で指定した要素を元にしたい場合です。
|
6
8
|
|
7
9
|
|
8
10
|
|
9
11
|
```
|
10
12
|
|
11
|
-
<input id="s
|
13
|
+
<input id="first_zip" type="text" name="1人目の郵便番号">
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
<select id="mode">
|
18
|
+
|
19
|
+
<option value="1">1人目と同じ</option>
|
20
|
+
|
21
|
+
<option value="1">直接入力</option>
|
22
|
+
|
23
|
+
</select>
|
24
|
+
|
25
|
+
<input id="second_zip" type="text" name="2人目の郵便番号">
|
12
26
|
|
13
27
|
```
|
14
28
|
|
15
29
|
|
16
30
|
|
17
|
-
|
31
|
+
selectのイベントは省きますが、次の様に処理を書くと値が代入されません。
|
18
32
|
|
19
|
-
|
33
|
+
|
20
34
|
|
21
35
|
```
|
22
36
|
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
```
|
22
22
|
|
23
|
-
let sample = document.getElementId('sample')
|
23
|
+
let sample = document.getElementbyId('sample')
|
24
24
|
|
25
25
|
if(! sample.value) {
|
26
26
|
|
@@ -36,9 +36,9 @@
|
|
36
36
|
|
37
37
|
```
|
38
38
|
|
39
|
-
if(! document.getElementId('sample').value) {
|
39
|
+
if(! document.getElementbyId('sample').value) {
|
40
40
|
|
41
|
-
document.getElementId('sample').value = '値代入'
|
41
|
+
document.getElementbyId('sample').value = '値代入'
|
42
42
|
|
43
43
|
}
|
44
44
|
|