Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How jQuery hides and shows HTML elements

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

这篇文章给大家分享的是有关jQuery如何隐藏和显示HTML元素的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

jQuery 效果

jQuery 可以有多种效果:隐藏、显示、切换,滑动,淡入淡出,以及动画,等等!

jQuery hide() 简单实例

$(document).ready(function(){ $("p").click(function(){ $(this).hide(); });});

如果您点击我,我会消失。

点击我,我会消失。

也要点击我哦。

注释:本实例演示了一个简单的 jQuery hide() 方法。下面的实例演示如何隐藏部分文本:

$(document).ready(function(){ $(".ex .hide").click(function(){ $(this).parents(".ex").hide("slow"); });}); div.ex { background-color:#e5eecc; padding:7px; border:solid 1px #c3c3c3;}中国办事处 隐藏

联系人:张先生北三环中路 100 号北京

美国办事处 隐藏

联系人:David第五大街 200 号 纽约

jQuery hide() 和 show()

通过 jQuery,您可以使用 hide() 和 show() 方法来隐藏和显示 HTML 元素,语法如下:

$(selector).hide(speed,callback);$(selector).show(speed,callback);

可选的 speed 参数规定隐藏/显示的速度,可以取以下值:"slow"、"fast" 或毫秒。

可选的 callback 参数是隐藏或显示完成后所执行的函数名称。

$(document).ready(function(){ $("#hide").click(function(){ $("p").hide(); }); $("#show").click(function(){ $("p").show(); });}); 如果点击"隐藏"按钮,我就会消失。

隐藏 显示

下面的例子演示了带有 speed 参数的 hide() 方法:

$(document).ready(function(){ $("button").click(function(){ $("p").hide(1000); });}); 隐藏

这是一个段落。

这是另一个段落。

jQuery toggle()

通过 jQuery,您可以使用 toggle() 方法来切换 hide() 和 show() 方法。语法如下:

$(selector).toggle(speed,callback);

可选的 speed 参数规定隐藏/显示的速度,可以取以下值:"slow"、"fast" 或毫秒。

可选的 callback 参数是 toggle() 方法完成后所执行的函数名称。

$(document).ready(function(){ $("button").click(function(){ $("p").toggle(); });}); 切换

这是一个段落。

这是另一个段落。

注释:点击切换按钮会隐藏已显示的元素,再次点击则会显示被隐藏的元素。

感谢各位的阅读!关于"jQuery如何隐藏和显示HTML元素"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report