隐藏/显示div在图像上单击jQuery?
问题描述:
点击图片时,我试图显示/隐藏div.当我单击图像时,没有任何反应.我的代码有什么问题
I am trying to show/hide div when click on an image. when I click on the image nothing happens. What is wrong with my code
<script type="text/javascript">
$('#close').click(function(){
$('#main').show();
$('#login').hide();
});
</script>
<div style="float:right;"><a href="#">Close <img id="close" src="assets/close.png"></a></div>
答
<script type="text/javascript">
$(function(){
$('#close').live('click',function(){
$('#main').show();
$('#login').hide();
});
});
</script>
<div style="float:right;"><a id="close">Close <img src="assets/close.png" /></a></div>
使用实时功能. 另外,我将目标定位在一个标签上,以便文本也可以触发它.
Use the live function. Also, I would target the a tag so the text also triggers it.