jQuery中hasClass()的意思及用法详解


本文摘自PHP中文网,作者藏色散人,侵删。

本篇文章主要给大家介绍jQuery中hasClass()用法介绍,希望对需要的朋友有所帮助!

hasclass什么意思?

hasClass()是jQuery中的一个内置方法,用于检查具有指定类名的元素是否存在。

语法:

1

$(selector).hasClass(className);

参数:它接受一个“className”参数,该参数指定需要在所选元素中搜索的类名。

返回值:如果搜索成功,返回true,否则返回false。

jQuery hasClass()方法的使用示例:

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

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

<html>

 

<head>

    <meta charset="UTF-8">

    <script

            src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">

    </script>

    <script>

        $(document).ready(function() {

            $("button").click(function() {

                alert($("p").hasClass("find"));

            });

        });

    </script>

    <style>

        .find {

            font-size: 120%;

            color: green;

        }

 

        body {

            width: 50%;

            height: 200px;

            border: 2px solid green;

            padding: 20px;

        }

    </style>

</head>

 

<body>

 

<h1>标题1</h1>

 

<p class="find">PHP中文网!</p>

<p>这是普通段落</p>

 

<button>点击我!</button>

 

</body>

 

</html>

输出:

阅读剩余部分

相关阅读 >>

jQuery如何判断单选框是否选中

jQuery中this和$(this)的区别是什么?

jq如何改变css样式宽度

jQuery中的ajaxerror()方法怎么用

jQuery 判断是否汉字的方法

jQuery primeui是什么?

通过jQuery怎么移除点击事件

有哪些常用的jQuery ui框架

两分钟了解jQuery与javascript、js 三者间的区别

jQuery中easyui是什么

更多相关阅读请进入《jQuery》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...