[英]on button click display hidden div and change image?
<div class="mac_1 tab_1 ipad_1" style=" float:right; margin:10px 20px 0 0;border:1px solid red; display: none;"></div>
<img src="images/mackbook.png" id="image"/>
<a href="#" id="mac" class="button facebook" style="width:120px; padding: 10px 0px; float:left; font: bold 22px 'Open Sans', sans-serif Helvetica, Clean, sans-serif;" OnClick="action();">Mackbook</a>
<a href="#" class="button facebook" style="width:80px; padding: 10px 0px; float:left; font: bold 22px 'Open Sans', sans-serif Helvetica, Clean, sans-serif;" OnClick="action1();">Tablet</a>
<a href="#" class="button facebook" style="width:80px; padding: 10px 0px; float:left; font: bold 22px 'Open Sans', sans-serif Helvetica, Clean, sans-serif;" OnClick="action2();">iPad</a>
</div>
How to show the div .mac_1 and change the source of the image on button click. 如何在单击按钮时显示div .mac_1并更改图像源。
Try it with this jQuery snippet: 尝试使用以下jQuery代码段:
$(document).ready(function(){
$("#button").click(function(){
$(".mac_1").css("display","block");
$("#image").src("yourSource");
});
});
Assuming you want to change the src of the image #image, and show your wrapper div .mac_1. 假设您想更改图像#image的src,并显示包装div .mac_1。
UPDATE UPDATE
Would be better to place the inline styles to class "show" in css file. 最好将内联样式放在css文件中的“ show”类中。 Then you could go:
然后您可以去:
...
$(".mac_1").addClass("show");
...
Would be the better approach. 会是更好的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.