我需要在单击另一个 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();
将显示它。
在几个函数中使用这两个函数,然后从按钮上的单击事件调用它们,应该会为您提供所需的内容。
我不提供完整的代码解决方案,因为这很简单,您应该能够自己遵循文档。
这里是文档的链接,以便您阅读:
关于javascript - 在 div 之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46098313/