簡體   English   中英

如何使用javascript將圖片制作為鏈接,然后鏈接到另一張圖片?

[英]How do I make an image into a link, that links to another image, using javascript?

這是我到目前為止所獲得的,而且我似乎無法使其正常工作。

當您單擊另一幅圖像時,它就是具有id="hap_text"的圖像。

<script>
$(function() {
    $('.touch_bg #touch_hap').click(function(e) {
        e.preventDefault();
        $('#hap_text').toggleClass('hidden');
    });
});
</script>

<div class="container touch_bg">
    <div>
        <a href="#"><img id="touch_hap" src="img/info/lefttouch.png"></a>
        <img id="hap_text" class="hidden" src="img/info/habitattext.png">
    </div>
</div>

和的CSS是:

.hidden {
    display: none;
}

未捕獲的ReferenceError:未定義$

不要忘了包括jQuery。 否則,您的代碼看起來不錯。

<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>

 $(function() { $('.touch_bg #touch_hap').click(function(e) { e.preventDefault(); $('#hap_text').toggleClass('hidden'); }); }); 
 .hidden { display: none; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="container touch_bg"> <div> <a href="#"> <img id="touch_hap" src="img/info/lefttouch.png"> </a> <img id="hap_text" class="hidden" src="img/info/habitattext.png"> </div> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM