jQuery 属性/过滤选择器

  • 过滤选择器主要是通过特定的过滤规则来筛选出所需的 DOM 元素, 该选择器都以 “:” 开头
  • 属性过滤选择器的过滤规则是通过元素的属性来获取相应的元素
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery引入文件/jquery-1.8.2.js"></script>

    <script>
        $(function() {
            // 属性过滤选择器的过滤规则是通过元素的属性来获取相应的元素

            // 获取所有id
            console.log($("div[id]"));
            // 获取name里含有newsletter的属性
            console.log($("input[name=newsletter]"));
            // 不等于
            console.log($("input[name!=newsletter]"));
            // 以什么开始的查询
            console.log($("input[name^=news]"));
            // 获取末尾带有s的
            console.log($("input[name$=s]"));
            // 查询所有news的
            console.log($("input[name*=news]"));


            //  选择器主要对所选择的表单元素进行过滤

            // 查询可用的元素
            console.log($("input:enabled"));
            // 匹配所有不可用的元素
            console.log($("input:disabled"));
            // 匹配被选中的元素
            console.log($("input:checked"));
            // 匹配所有选中的option里的selected被选中的
            console.log($("select option:selected"));
            // 匹配到所有的input
            console.log($(":input"));
            // 匹配到text的
            console.log($(":text"));

        })
    </script>
</head>

<body>
    <div id="a"></div>
    <div id="b"></div>
    <input type="text" name="news">
    <input type="text" name="news" id="" disabled="disabled">
    <input type="text" name="newsletter" id="" value="" placeholder="这个没有结尾的s哦🐖">
    <input type="text" name="s">
    <input type="checkbox" checked="checked">
    <input type="checkbox">
    <select name="" id="">
        <option value="">😄</option>
        <option value="" selected="">🐖</option>
    </select>

</body>

</html>

通过控制台查看哟~
在这里插入图片描述

  • 13
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值