如果您只单击标题,我将尝试隐藏div。但我的过滤器似乎不起作用。无论我在哪里单击div,我都会得到预期的函数。
<div class="post" onclick="updatenext()">
<h2>Item3</h2>
</div>
<div class="post" onclick="updatenext()">
<h2>Item4</h2>
</div>
<script>
var index=0;
$(".post").hide();
$(".post").eq(0).show();
// Tried this too: $(".post").filter(":header")....
$(":header.post").on("click",
function () {
index=$(this).index();
//console.log($(this).index());
$(this).hide();
$(".post").eq(index).show();
}
);
</script>
我希望只有在单击每个div中的header元素时,单击才会起作用。