jQuery如何选择以特定字符开头的ID元素


当前第2页 返回上一页

示例:选择id以“demo”开头的元素并更改其背景颜色

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

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<style>

            #demo_div {

                background: green;

                height: 100px;

                width: 200px;

                margin: 0 auto;

                color: white;

                line-height: 100px;

            }

        </style>

           

        <script src="https://code.jquery.com/jquery-1.10.2.js"></script>

    </head> 

       

    <body style = "text-align:center;"

        <div id = "demo_div"> 这是div盒。</div>

        <p id = "demo_p" style ="font-size: 19px; font-weight: bold;"></p>

        <button onClick = "GFG_Fun()">点击这里</button>

           

        <p id = "demo_DOWN" style = "color: white; font-size: 24px; font-weight: bold;"> </p>

           

        <script>

            $('#demo_p').text("点击按钮,选择id以“demo”开头的元素并更改背景色。");

            function GFG_Fun() {

                $( "[id^='demo']" ).css("background-color", "pink");

                $('#demo_DOWN').text("测试文字!");

            }

        </script> 

    </body> 

</html>

输出:

b3ca4d5a84aa9d260f7eec9833ab8d4.png

相关免费学习推荐:javascript(视频)

以上就是jQuery如何选择以特定字符开头的ID元素的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

jQuery怎么删除html元素

使用jQuery怎么获取url参数?

jQuery javascript ajax区别是什么

不同的jQuery版本冲突怎么办

ajax与jQuery的区别是什么

jQuery发请求传输中文参数乱码怎么办

jQuery和document获取html元素的区别是什么?

如何用jQuery实现随机数

jQuery怎么移除css样式

jQuery怎么去除css属性

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




打赏

取消

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

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

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

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

评论

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