如果我将 .thumbnail div 放在 #thumbhider 和 #thumbcontent div 之外,则单击事件可以正常工作并按预期进行。目前他们没有。
网址:http://www.samcoles.co.uk/dustbowl/guitars.php
我猜这与包含 div 上的溢出有关:隐藏?我该如何解决这个问题?
JavaScript:
//this is within $(document).ready function
$(".thumbnail").click(function () {
var IMAGE_DIR = "images/guitars/";
var img = $(this).find("img").attr("alt");
$("#mainphoto").attr("src", IMAGE_DIR + img);
if(captions) {
$("#imgcaption").text(captions[img]);
}
});
CSS:
div.thumbnail { background-color: #000000; padding: 1px; float: left; width: 69px; height: 69px; cursor: pointer; }
div#thumbhider { width: 673px; height: 70px; overflow: hidden; margin: 0 auto; margin-top: 19px; position: relative; }
div.thumbcontent { height: 70px; background-color: #00ff00; width: 0 auto; display: inline; position: relative; }
html:
<div id="thumbhider">
<div class="thumbcontent">
<div style="margin-right:15px;" class="thumbnail"><img alt="1.png" src="thumber.php?img=images/guitars/1.png&h=69&w=69"></div>
<div style="margin-right:15px;" class="thumbnail"><img alt="10.png" src="thumber.php?img=images/guitars/10.png&h=69&w=69"></div>
<!--etc....-->
<div style="clear:both;"></div>
</div>
</div>
最佳答案
从 div.thumbcontent
中删除 position:relative
div.thumbcontent {
height: 70px;
background-color: lime;
width: 0 auto;
display: inline;
/*position:relative*/
}
关于jquery - 点击事件不会在内部 div 上触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12789381/