$(function() {
$('.entry-title').click(function() {
var clicked = this; // take a reference of clicked element
// to use it within hide() callback scope
// hide all visible sections
$('.toggle-section:visible').hide(function() {
// show the clicked
$(clicked).closest('.post').find('.toggle-section').slideDown();
});
return false;
});
});
您应该将所有代码汇总为两部分:
<script type="text/javascript">
$(function() {
$('.toggle-section').hide(); // initial hide
$('.entry-title').click(function() {
var clicked = this; // take a reference of clicked element
// to use it within hide() callback scope
// hide all visible sections
$('.toggle-section:visible').hide(function() {
// show the clicked
$(clicked).closest('.post').find('.toggle-section').slideDown();
});
return false;
});
});
</script>