![](/img/trans.png)
[英]How do I create a random link out of specified group of links using within an image using 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.