2014-10-28 50 views
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"> 
+1

你是什麼意思的「不工作」? – 2014-10-28 16:17:34

+0

什麼是「#link」元素 - 你可以發佈一些HTML – Shai 2014-10-28 16:17:55

+0

它甚至會進入第二個if語句嗎?您應該使用console.log進行測試,以查看在$('#nextQ')開頭處設置的「actual」值。click(function(){})函數。 – 2014-10-28 16:21:02

回答

0

因爲#link是一個形象,你不能把它裏面任何東西。你需要圍繞它包裝<a>。好東西jQuery有!

$('#link').wrap('<a href="http://www.google.com">'); 
+0

仍然無法使用。 – moss 2014-10-28 16:42:37