-
Notifications
You must be signed in to change notification settings - Fork 0
/
prac9-1.html
45 lines (44 loc) · 1.14 KB
/
prac9-1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>라디오 버튼을 클릭하면 이미지를 출력</title>
<script>
function show(obj) {
let newimg = document.getElementById("newimg");
if (newimg) {
newimg.parentElement.removeChild(newimg);
}
let img = new Image();
let parent = document.getElementById("parent");
img.src = obj.value;
img.setAttribute("id", "newimg");
parent.appendChild(img);
}
</script>
</head>
<body>
<h3>버튼을 누르면 라디오 버튼의value를 출력</h3>
<hr />
<form id="parent">
<input
type="radio"
name="fruits"
value="./fruit/banana.jpeg"
onclick="show(this)"
/>바나나
<input
type="radio"
name="fruits"
value="./fruit/mango.jpeg"
onclick="show(this)"
/>망고
<input
type="radio"
name="fruits"
value="./fruit/apple.jpeg"
onclick="show(this)"
/>사과 <br /><br />
</form>
</body>
</html>