Commit 2d157ec6 authored by baesangjune's avatar baesangjune
Browse files

parent 798393cf
......@@ -21,17 +21,18 @@ class Quiz extends React.Component {
i: 0,
page: 0,
}
this.textInput = React.createRef()
// this.textInput = React.createRef()
}
ShowQuiz() {
this.setState({ page: 1 })
}
setQuestion() {
//값이 입력되지 않은채로 넘겨졌을 때 문제 해결 해야 함-sj-
this.setState({ ...question[this.state.i + 1], i: this.state.i + 1 })
}
//answerbox - answer박스의 값을 네임리스트로 받아와서 값을 localstorage에 저장
answerbox() {
let answers = document.getElementsByName('answer');
let count = answers.length
......@@ -42,7 +43,7 @@ class Quiz extends React.Component {
if (answers[i].checked) {
// checked_index = i;
checked_value = answers[i].value;
localStorage.setItem('answer'+i, checked_value)
localStorage.setItem('answer-'+i, checked_value)
}
}
// alert('선택된 항목 인덱스: ' + checked_index + '\n선택된 항목 값: ' + checked_value);
......@@ -64,6 +65,7 @@ class Quiz extends React.Component {
// }
render() {
if (this.state.page === 1) {
this.answerbox()
if (this.state.i === question.length) {
return (
<div>
......@@ -77,9 +79,9 @@ class Quiz extends React.Component {
<h2>Q:{this.state.Q}</h2>
{this.state.Choose.map((a) =>
<div>
<input type="radio" name='answer' id={a} value={a} ref={this.textInput}/>
<input type="radio" name='answer' id={a} value={a} /*ref={this.textInput}*/ />
<label for={a}>{a}</label>
{this.answerbox()}
</div>)}
<div className="App">
......@@ -88,7 +90,7 @@ class Quiz extends React.Component {
{/* <div>
<input type="text" value={this.state.v} name="A" onChange={this.setAnswer} />
</div> */}
<button type="button" onClick={this.setQuestion}>다음</button>
<button type="button" onClick={setTimeout(this.setQuestion, 2000)}>다음</button>
</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