gpt4 book ai didi

jquery - 将子 div11 显示在与另一个子标签 p 相同的父 div 中

转载 作者:行者123 更新时间:2023-12-01 06:52:09 28 4
gpt4 key购买 nike

我想通过单击父 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>

最佳答案

我想你想要这样的东西,请参阅 .next().nextAll()在 jquery 文档中。

$("div p").click(function(){
$(this).hide().next().show();
});

关于jquery - 将子 div11 显示在与另一个子标签 p 相同的父 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13238189/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com