很抱歉问了更多关于同一场景的问题,但这里是:
我的文字很棒,图像放置得很好,但是,我不想在单击图像时运行 jquery slide 方法(那些被保存用于其他功能)。是否可以使幻灯片功能仅在单击图像左侧的“ block ”时运行?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
</script>
<body>
<div id="flip">
<div id="flipBox"><p>Click to slide the panel down or up</p></div>
<img class="ux" src="http://placekitten.com/32/32" alt="complete" height="32" width="32" align="right" />
<img class="ux" src="http://placekitten.com/32/32" alt="add" height="32" width="32" align="right" />
<img class="ux" src="http://placekitten.com/32/32" alt="edit" height="32" width="32" align="right" />
<img class="ux" src="http://placekitten.com/32/32" alt="remove" height="32" width="32" align="right" />
</div>
<div id="panel">Hello world!</div>
</body>
这是 jfiddle 链接:http://jsfiddle.net/rvAPk/
我非常感谢 SO 的知识渊博的人!谢谢大家!
-阿杰
最佳答案
您可以使用 e.stopPropagation() :
Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
$("#flip img").click(function(e){
e.stopPropagation()
});
关于javascript - 如何 : Make a Div a link, 而不是其中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22522820/