如何在图像中添加链接?

时间:2014-10-28 16:15:15

标签: javascript

基本上我在这里做的是通过下一个箭头移动div /问题。当所有问题都完成后。下一个箭头消失,同一个箭头出现一个链接。目前它在滚动问题和箭头消失等方面起作用。但是谷歌的链接不起作用。

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 个答案:

答案 0 :(得分:0)

由于#link是图片,因此您无法在其中放置任何内容。您需要将<a>包裹起来。好的东西jQuery有这个!

$('#link').wrap('<a href="http://www.google.com">');
相关问题