我想通过点击父div(1或2或3)中的(p)标签隐藏p,p将消失,div div(11或12或13)p将按照p出现在那个师中消失了。
如何在不使用ID名称的情况下执行此操作?
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
$("div p").click(function(){
$(this).hide();
//What do I need to put here?? to show the <p> in the <div id="11 or 12 or 13"> according to the <p> that is clicked
});
});
</script>
</head>
<body>
<div class = "" id="1">
<p>If you click on me, I will disappear.</p> // BY CLICKING THIS P HIDE IT THEN
<div id="11" style="display:none;">
<p>You have clicked me<p> // THEN SHOW THIS P
</div>
</div>
<span> HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH </span>
<div id="2">
<p>Click me away!</p>
<div id="22" style="display:none;">
<p>You have clicked me too!<p>
</div>
</div>
<span> HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH </span>
<div id="3">
<p>Click me too!</p>
<div id="33" style="display:none;">
<p>You have clicked me three!<p>
</div>
</div>
<span> HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH </span>
</body>
</html>
答案 0 :(得分:3)
我认为您需要这样的内容,请参阅jquery doc中的.next()或.nextAll()。
$("div p").click(function(){
$(this).hide().next().show();
});
答案 1 :(得分:2)
为了制作div,在p show旁边你可以使用$(this).next()。show();