javascript - 在 div 之间切换

标签 javascript jquery html

我需要在单击另一个 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/

相关文章:

javascript - 什么可能在 JavaScript 中改组我的查询字符串参数构造函数?

javascript - 点击完成后调用函数

javascript - Jquery 和 CSS 加载不可靠

javascript - Google Docs 如何在 JavaScript 中全屏显示

html - 而最小高度为 : 100% not expand when it's content grows to large 的 div

javascript - 如果每个字符串包含 jQuery 中的特定字符,则打印每个字符串?

javascript - 我如何重新定义 myObject 的主要功能,e。 G。 myObject() 在不损坏 myObject 的属性的情况下做了什么,e。 G。我的对象.foo?

JavaScript 多类失败

javascript - jquery rain datepicker firefox CSS 不工作

html - 用自定义符号替换列表元素符号(右对齐)