我正在爲用戶回答三個問題的公司進行測驗,如果他們都是正確的,他們應該被重定向到他們填寫他們的聯繫信息的頁面有機會贏得獎品。 如果一個或多個問題的回答錯誤,則應將其重定向到另一個頁面。如何知道哪些單選按鈕被檢查並正確重定向
我需要標記正確的答案,然後檢查它們。 如果所有問題都回答的是:重定向到motivering.html 如果一個或多個問題是錯誤的:重定向到tyvarr.html
我試圖檢查的值,僅拿出了這一點。這是不正確的,我幾乎可以肯定這不是最合適的方式。
jQuery的
$(document).ready(function() {
$('#questions input').on('change', function() {
console.log($('input[name=questionOne]:checked', '#questions').val());
console.log($('input[name=questionTwo]:checked', '#questions').val());
console.log($('input[name=questionThree]:checked', '#questions').val());
});
});
我的標記 - HTML
<form method="POST" id="questions">
<div class="form-group" id="questionOne">
<h3>Question 1</h3>
<div class="radio">
<input type="radio" name="questionOne" id="question1" class="radio" value="1" required/>
<label for="question1">Option 1</label>
</div>
<div class="radio">
<input type="radio" name="questionOne" id="question2" class="radio" value="2"/>
<label for="question2">Option 2 - Right answer</label>
</div>
<div class="radio">
<input type="radio" name="questionOne" id="question3" class="radio" value="3"/>
<label for="question3">Option 3</label>
</div>
</div>
<div class="form-group" id="questionTwo">
<h3>Question 2</h3>
<div class="radio">
<input type="radio" name="questionTwo" id="question4" class="radio" value="4" required/>
<label for="question4">Option 1</label>
</div>
<div class="radio">
<input type="radio" name="questionTwo" id="question5" class="radio" value="5"/>
<label for="question5">Option 2</label>
</div>
<div class="radio">
<input type="radio" name="questionTwo" id="question6" class="radio" value="6"/>
<label for="question6">Option 3 - Right answer</label>
</div>
</div>
<div class="form-group" id="questionThree">
<h3>Question 3</h3>
<div class="radio">
<input type="radio" name="questionThree" id="question7" class="radio" value="7" required/>
<label for="question7">Option 1</label>
</div>
<div class="radio">
<input type="radio" name="questionThree" id="question8" class="radio" value="8"/>
<label for="question8">Option 2 - Right answer</label>
</div>
<div class="radio">
<input type="radio" name="questionThree" id="question9" class="radio" value="9"/>
<label for="question9">Option 3</label>
</div>
</div>
<div class="buttons">
<a href="index.html" class="btn btn-default form_button_cancel">Avbryt</a>
<button type="submit" class="btn btn-default form_button_next">Nästa</button>
</div>
</form>
我的風格 - CSS
@charset "utf-8";
/* CSS Document */
/* FONT */
@import url('https://fonts.googleapis.com/css?family=Nunito:400,700');
body, textarea, input{
font-family: 'Nunito', sans-serif;
font-weight:400;
font-size:16px;
line-height:26px;
letter-spacing:0.5px;
}
/*.start{
background-color:tomato;
}*/
h1, h2, h3, .form_button_start, .form_button_cancel, .form_button_next{
font-family: 'Nunito', sans-serif;
font-weight:600;
}
h1, h2, h3{
text-transform:uppercase;
}
h3{
font-size:21px;
margin-top:50px;
}
textarea{
resize:none;
}
ul{
list-style:none;
}
.radio label {
width: 100%;
border-radius: 3px;
border: 1px solid #D1D3D4
}
/* hide input */
input.radio:empty {
margin-left: -999px;
}
/* style label */
input.radio:empty ~ label {
position: relative;
line-height: 3.5em;
text-indent: 2em;
margin-top: 1em;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
font-size:16px;
text-transform:uppercase;
}
input.radio:empty ~ label:before {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0;
content: '';
width: 2.5em;
background: #D1D3D4;
border-radius: 3px 0 0 3px;
}
/* toggle hover */
input.radio:hover:not(:checked) ~ label:before {
/*content:'\2714';*/
text-indent: .9em;
color: #C2C2C2;
}
input.radio:hover:not(:checked) ~ label {
color: #888;
}
/* toggle on */
input.radio:checked ~ label:before {
/*content:'\2714';*/
text-indent: .9em;
color: #9CE2AE;
background-color: #4DCB6D;
}
input.radio:checked ~ label {
color: #333;
}
/* radio focus */
input.radio:focus ~ label:before {
box-shadow: 0 0 0 3px #999;
}
/* Butto style */
.form_button_cancel, .form_button_next, .form_button_start{
width: 200px;
text-transform: uppercase;
line-height: 30px;
margin: 20px 0;
}
.form_button_start{
background-color:green;
border:0px solid transparent;
}
.form_button_next{
background-color: green;
float:right;
border:0px solid transparent;
}
.form_button_cancel{
float:left;
}
有沒有辦法得到這個觸發點擊下一步按鈕,而不是當一個人已經回答了三個問題觸發? –
我做了涵蓋的編輯。 –