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

<div id="newpost">

推荐答案

看看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');
    });
});

For reference, kindly check this demo

Jquery相关问答推荐

使用 howler.js 中的变量播放多种声音

如果选中了三个sibling ,则选中一个复选框

哪个 JQuery Select 器会排除与给定 Select 器匹配的父项的项目?

禁用提交按钮,直到所有字段都有值

使用淡入淡出和追加

jQuery 与 ExtJS

使用 jQuery click 处理锚点 onClick()

如何在单击时 Select 多选 Select 框的所有选项?

带有 jquery.animate() 的 CSS 旋转跨浏览器

如何使用 Twitter Bootstrap 自动关闭alert

在jquery中查找具有某个属性值的所有元素

jQuery $(".class").click(); - 多个元素,点击事件一次

如何通过jQuery函数仅获取直接子元素

jQuery:如何找到父母的特定子元素?

更改 div 的内容 - jQuery

如何在按键事件后获取 jQuery .val()?

jQuery DataTables:控制表格宽度

jQuery .each() 索引?

Twitter Bootstrap 中的树

IE 中带有 jQ​​uery ajax 调用的无传输错误