In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
本篇内容主要讲解"jquery如何实现显示与隐藏的互换",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"jquery如何实现显示与隐藏的互换"吧!
互换方法:1、用"元素对象.toggle()",当元素是可见状态则隐藏元素,当元素不可见则显示元素;2、用"元素对象.slideToggle()",当元素可见则隐藏元素,当元素不可见则显示元素;3、用"元素对象.fadeToggle()"。
本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
jquery实现显示与隐藏互换有三种方法:
toggle() 方法
slideToggle() 方法
fadeToggle() 方法
1、toggle() 方法
toggle() 方法在被选元素上进行 hide() 和 show() 之间的切换。
该方法检查被选元素的可见状态。如果一个元素是隐藏的,则运行 show(),如果一个元素是可见的,则运行 hide() - 这会造成一种切换的效果。
注释:隐藏的元素不会被完全显示(不再影响页面的布局)。
$(document).ready(function() { $("button").click(function() { $("p").toggle(); }); });
这是一个段落。
切换 hide() 和 show()
2、slideToggle() 方法
slideToggle() 方法在被选元素上进行 slideUp() 和 slideDown() 之间的切换。
该方法检查被选元素的可见状态。如果一个元素是隐藏的,则运行 slideDown(),如果一个元素是可见的,则运行 slideUp() - 这会造成一种切换的效果。
$(document).ready(function() { $("button").click(function() { $("p").slideToggle(); }); });
这是一个段落。
切换 slideUp() 和 slideDown()
3、fadeToggle() 方法
fadeToggle() 方法在 fadeIn() 和 fadeOut() 方法之间切换。
如果元素是淡出显示的,fadeToggle() 会使用淡入效果显示它们。
如果元素是淡入显示的,fadeToggle() 会使用淡出效果显示它们。
注释:隐藏的元素不会被完全显示(不再影响页面的布局)。
$(document).ready(function() { $("button").click(function() { $("#div1").fadeToggle(); $("#div2").fadeToggle("slow"); $("#div3").fadeToggle(3000); }); });
实例演示了 fadeToggle() 使用了不同的 speed(速度) 参数。
点击淡入/淡出
到此,相信大家对"jquery如何实现显示与隐藏的互换"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.