我是靠谱客的博主 饱满花生,这篇文章主要介绍jquery怎样实现点击显示点击其他地方隐藏,现在分享给大家,希望可以做个参考。

本教程操作环境:windows10系统、jquery3.2.1版本、Dell G3电脑。

jquery怎样实现点击显示点击其他地方隐藏

在jquery中,可以利用click方法、:not选择器、hide()和show()方法来实现点击显示点击其他地方隐藏效果。

下面我们通过示例看一下怎样点击按钮元素显示,点击除了按钮的元素时元素隐藏。

示例如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("body *:not(.intro)").click(function(){ $("div").hide(); }); $(".intro").click(function(){ $("div").show(); }); }); </script> <style type="text/css"> div{ width:200px; height:200px; background-color:red; } </style> </head> <body> <div></div> <button class="intro">按钮</button> </body> </html>
登录后复制

输出结果:

+11.gif

相关视频教程推荐:jQuery视频教程

以上就是jquery怎样实现点击显示点击其他地方隐藏的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是饱满花生最近收集整理的关于jquery怎样实现点击显示点击其他地方隐藏的全部内容,更多相关jquery怎样实现点击显示点击其他地方隐藏内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部