切换显示/隐藏div与按钮? [英] toggle show/hide div with button?

查看:154
本文介绍了切换显示/隐藏div与按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望这是一个容易的问题。我有一个div,我想用一个按钮切换隐藏/显示。

 < div id =newpost 


解决方案

查看jQuery切换



HTML:

 < div id ='content'> Hello World< / div> 
< input type ='button'id ='hideshow'value ='hide / show'>



jQuery

  jQuery(document).ready(function(){
jQuery('#hideshow')。live('click',function(event){
jQuery('#content')。toggle('show');
});
});

对于jQuery 1.7和更新版本,使用

  jQuery(document).ready(function(){
jQuery('#hideshow')。 ('#content')。toggle('show');
});
});

演示


Hopefully this is an easy question. I have a div that I want to toggle hidden/shown with a button.

<div id="newpost">

解决方案

Look at jQuery Toggle

HTML:

<div id='content'>Hello World</div>
<input type='button' id='hideshow' value='hide/show'>

jQuery:

jQuery(document).ready(function(){
    jQuery('#hideshow').live('click', function(event) {        
         jQuery('#content').toggle('show');
    });
});

For versions of jQuery 1.7 and newer use

jQuery(document).ready(function(){
        jQuery('#hideshow').on('click', function(event) {        
             jQuery('#content').toggle('show');
        });
    });

Demo

这篇关于切换显示/隐藏div与按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆