我有一個測驗佈局,從數據庫中獲取問題和答案。隱藏點擊並顯示另一個直到最後
我目前有一個下一個按鈕來通過這些問題,但我想這樣做,所以當選擇一個答案時,它會轉到下一個問題。
每個問題/答案集都有這個div,id是問題的ID。
<div class="question container center" id="1" style="display: none;">
<h1>Question</h1>
Answer
Answer
Answer
Answer
</div>
答案按鈕看起來是這樣的:
<a class="waves-effect waves-light btn-large blue-grey lighten-2 btn-width mcqtest">Answer</a>
使用當前Jquery的IM是這樣的:
$('#2, #3, #4, #5, #6, #7, #8, #9, #10, #11, #12, #13, #14, #15, #16, #17, #18, #19, #20, #21, #22, #23, #24, #25 ').hide();
$('#next').click(function(){
//code
var curr = $(".question:visible");
var next = curr.next(".question");
next.show();
curr.hide();
if (!next.next(".question").length) {
$("button").attr('disabled', 'disabled');
$("button").text("End of Test");
}
});
重要的是,'id's不應該以數字開頭。 – RRK
答案的元素類型是什麼? –
答案只是風格的標籤 – JohnyChew