简体   繁体   English

想用jQuery显示和隐藏div

[英]want to show and hide div with jquery

I am completely new to jquery, and don't understand it 100%. 我对jquery完全陌生,并且100%都不了解。 What I want is a div containing text or an image, and when you click on it, it will show another div. 我想要的是一个包含文本或图像的div,当您单击它时,它将显示另一个div。

HTML: HTML:

 <div class="mytrigger">click here</div>
 <div class="mycontent">show this when clicking on the above</div>

Jquery: jQuery:

<script>
 $( ".mytrigger" ).click(function() {
   $( ".mycontent" ).toggle( "slow", function() {
   });
 });
</script>

so, when you click on "mytrigger", it must show "mycontent. 因此,当您单击“ mytrigger”时,它必须显示“ mycontent。

Just leave the function inside your toggle-call away: 只需将函数保留在您的切换调用中即可:

$(function() {
    $( ".mytrigger" ).click(function() {
        $(".mycontent").toggle("slow");
    });
});

See: http://jsfiddle.net/a8Np4/3/ 请参阅: http//jsfiddle.net/a8Np4/3/

Edit: Wrapped in a DOM-Ready-Call 编辑:包裹在DOM就绪调用中

It is working fine now 这是工作的罚款,现在

You might need to put your Jquery inside 您可能需要将Jquery放入其中

$(document).ready(function()
{
  //Your code here
}

Also just hide the second div initially adding a display:none style to mycontent class. 也可以隐藏第二个div,最初在mycontent类中添加display:none样式。

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

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