Commit aebc0b83 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

radio button reset

parent 3fbe99fd
...@@ -23,7 +23,7 @@ function Home() { ...@@ -23,7 +23,7 @@ function Home() {
else if (!password) { else if (!password) {
alert('비밀번호를 입력하세요') alert('비밀번호를 입력하세요')
} }
else if (password !== '0319') { else if (password !== '0000') {
alert('유효한 비밀번호를 입력하세요') alert('유효한 비밀번호를 입력하세요')
} }
else { else {
......
import React, { useState } from 'react' import React, { useState } from 'react'
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import Timer from 'react-compound-timer'; // 타이머쓰기위해 import import Timer from 'react-compound-timer'; // 타이머쓰기위해 import
import logo from './img_question.png' import logo from './img/img_question.png'
const QnA = [ const QnA = [
{ Q: "6 X 4 = ?", Choose: [6, 12, 18, 24], A: "4", N: 1 }, { Q: "6 X 4 = ?", Choose: [6, 12, 18, 24], A: "4", N: 1 },
...@@ -22,22 +20,21 @@ function Quiz() { ...@@ -22,22 +20,21 @@ function Quiz() {
page: 0, page: 0,
}) })
const [selected, setSelected] = useState("") //선택한 답을 보여줄 것들 const [selected, setSelected] = useState("") //선택한 답을 보여줄 것들
// const [checked, setChecked] = useState(false)
function handleQuestion() { function handleQuestion() {
setQuestion({ ...QnA[question.i + 1], i: question.i + 1, page: question.page + 1 }) setQuestion({ ...QnA[question.i + 1], i: question.i + 1, page: question.page + 1 })
// setChecked(false) setSelected("")
} }
let handleChange = (ev) => { let handleChange = (ev) => {
// ev.preventDefault() //새로고침 안되도록 // ev.preventDefault() //새로고침 안되도록
setSelected(ev.target.value) //selected값 변경 setSelected(ev.target.value) //selected값 변경
Answers[question.N - 1] = Number(ev.target.id) + 1 Answers[question.N - 1] = Number(ev.target.id) + 1
localStorage.setItem('Answers', JSON.stringify(Answers)) localStorage.setItem('Answers', JSON.stringify(Answers))
} }
return ( return (
<div className="container-fluid position-absolute"> <div className="container-fluid">
<div className="text-center h2 font-weight-bold bg-warning py-2">미적분학 퀴즈</div> <div className="text-center h2 font-weight-bold bg-warning py-2">미적분학 퀴즈</div>
<div className="row justify-content-md-center" > <div className="row justify-content-md-center" >
<div className="col text-right"> <div className="col text-right">
...@@ -53,7 +50,7 @@ function Quiz() { ...@@ -53,7 +50,7 @@ function Quiz() {
<form> <form>
{question.Choose.map((a, index) => {question.Choose.map((a, index) =>
<div key={index}> <div key={index}>
<input type="radio" name='answer' id={index} value={a} onClick={handleChange} /> <input type="radio" name='answer' id={index} value={a} onChange={handleChange} checked={parseInt(selected) === a} />
<label className="font-weight-bold" htmlFor={a}>{a}</label> <label className="font-weight-bold" htmlFor={a}>{a}</label>
</div> </div>
)} )}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment