简体   繁体   English

(JQUERY) 我想让一个不可见的 div 在点击时可见并在点击时再次隐藏它

[英](JQUERY) I want to make an invisible div visible on click and hide it again onclick

So i have a trouble in which i want to make my invisible "container" visible when i click on my "input type='submit'" and then close it again when i click on close but i cant seem to get it working.所以我有一个麻烦,当我点击我的“input type='submit'”时我想让我的隐形“容器”可见,然后当我点击关闭时再次关闭它,但我似乎无法让它工作。 HTML HTML

<div id="container">
    <a href="#"><span id="close"><em>x</em></span></a>
<div id="wrapper">
    <font id="wrapper-text"><em>Upload Your Own Video!</em></font>
    <input type="text" placeholder="Title for the video"><br>
    <input type="text" placeholder="User"><br>
    <input type="text" placeholder="Tags"><br>
    <textarea placeholder="Description for the video" rows="7" cols="40"></textarea>
</div>
</div>

CSS CSS

#container {display:none; height:707px; widht:100%; background-color:rgba(255,255,255,0.3)}

Script脚本

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" type="text/javascript">
     $(document).ready(function(){
        document.getElementById('#yourown').click(function(){
        document.getElementById("#container").css("display","block");
            )} 
        )}
     $document.ready(function(){
        document.getElementById("#close").click(function{
            document.getElementById("#container").css("display","none")
        })
     })

If you are using jQuery then the use of document.getElementById() is completely inane.如果您使用 jQuery,那么使用document.getElementById()是完全愚蠢的。
Just use this:只需使用这个:

$("#yourown").click(function(){
    $("#container").toggle();
});
$("#close").click(function(){
    $("#container").hide();
});

I'm not exactly sure that this is what you need, your code is kind of messy.我不确定这是否是您所需要的,您的代码有点混乱。 Try it out and see if it works.尝试一下,看看它是否有效。

If you are using jQuery, you probably want to use $('#container').show() and $('#container').hide().如果您使用 jQuery,您可能想要使用 $('#container').show() 和 $('#container').hide()。

I'd recommend reading up on them here:我建议在这里阅读它们

You're also missing some semicolons... Something like this should work:您还缺少一些分号......这样的事情应该有效:

    $('#yourown').click(function(){ 
        $("#container").show(); 
    });
    $("#close").click(function{ 
        $("#container").hide();
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM