用按钮切换显示/隐藏div? [英] toggle show/hide div with button?
本文介绍了用按钮切换显示/隐藏div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
希望这是一个简单的问题.我有一个 div
我想用按钮切换隐藏/显示
Hopefully this is an easy question. I have a div
that I want to toggle hidden/shown with a button
<div id="newpost">
推荐答案
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 和更新的版本使用
For versions of jQuery 1.7 and newer use
jQuery(document).ready(function(){
jQuery('#hideshow').on('click', function(event) {
jQuery('#content').toggle('show');
});
});
作为参考,请查看此demo
For reference, kindly check this demo
这篇关于用按钮切换显示/隐藏div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文