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

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