0
基本上我在这里做的是通过下一个箭头移动div /问题。当所有的问题都完成了。下一个箭头消失,并出现一个相同的箭头,其中有一个链接。目前它在滚动浏览问题和箭头消失等方面起作用。但是,与Google的链接不起作用。如何在图像中有链接?
var actual = 0; // select by default the first question
$(document).ready(function() {
var number_of_question = $('.question').length; // get number of questions
$('#link').hide();
$('.question:gt(' + actual + ')').hide(); // Hide unselect questions
$('#nextQ').click(function() {
if (actual < number_of_question - 1) {
changeQuestion(actual + 1); // display select question
}
if (actual === number_of_question - 1){
$('#previousQ').hide();
$('#nextQ').hide();
$('#digit').hide();
$('#ledgend').hide();
$('#question_number').hide();
$('#link').show();
$('#link').html('<a href="http://www.google.com">Google</a>');
document.getElementById("finished").style.backgroundColor="black";
}
});
$('#previousQ').click(function() {
if (actual) {
changeQuestion(actual - 1); // display select question
}
});
});
function changeQuestion(newQuestion) {
$('.question:eq(' + actual + ')').hide(); // hide current question
$('.question:eq(' + newQuestion + ')').show(); // show new question
actual = newQuestion; // memorize actual selection
$('#question_number').html(actual);
}
HTML
<input class="left_arrow1" id="link" type="image" src="images/right_arrow.png">
<input class="left_arrow" type="image" src="images/right_arrow.png" id="nextQ">
<input class="right_arrow" type="image" src="images/left_arrow.png" id="previousQ">
你是什么意思的“不工作”? – 2014-10-28 16:17:34
什么是“#link”元素 - 你可以发布一些HTML – Shai 2014-10-28 16:17:55
它甚至会进入第二个if语句吗?您应该使用console.log进行测试,以查看在$('#nextQ')开头处设置的“actual”值。click(function(){})函数。 – 2014-10-28 16:21:02