gpt4 book ai didi

javascript - 在 div 之间切换

转载 作者:行者123 更新时间:2023-11-28 17:48:52 25 4
gpt4 key购买 nike

我需要在单击另一个 div 中的按钮时隐藏这些 div,如下所示。当我单击另一个 div 中的 button 时,它会隐藏另一个 div 以及相反的部分。

<!DOCTYPE html>
<html lang="en">
<head>
<title>
tesing hide
</title>
<style>
#ticket, #usernamepassword { margin-top: 20px; width: 960px; color: navy; background-color: pink; border: 2px solid blue; padding: 5px; text-align: center; }
</style>

</head>

<center>
<div id="ticket">
<div> this is the content of my ticket div
</div>
<button>Show usernamepassword</button>

</div>

<div id="usernamepassword">
<div> this is the content of username and password div</div>
<button>Show ticket</button>
</div>
</center>
</html>

最佳答案

$( ".target" ).hide();

这将隐藏一个元素,类似地

$( ".target" ).show();

将显示它。

在几个函数中使用这两个函数,然后从按钮上的单击事件调用它们,应该会为您提供所需的内容。

我不提供完整的代码解决方案,因为这很简单,您应该能够自己遵循文档。

这里是文档的链接,以便您阅读:

http://api.jquery.com/show/

http://api.jquery.com/hide/

关于javascript - 在 div 之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46098313/

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