您的位置:首页 > Web前端 > JQuery

jquery属性过滤器

2018-03-26 20:19 441 查看
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
<meta charset="utf-8" />
    <script src="jquery-3.3.1.js"></script>
    <script>
        $(function () {
            $('#btn').click(function () {
                //有id属性的div
                //$('div[id]').css('backgroundColor', 'blue');

                //获取有id属性的div并且id属性为dv1
                //$('div[id=dv1]').css('backgroundColor', 'blue');

                //$('input[name=name]').css('backgroundColor', 'blue');
                //$('input[name!=name]').css('backgroundColor', 'blue');
                //name属性必须以name开头的
                //$('input[name^=name]').css('backgroundColor', 'blue');
                //name属性必须以name结尾的
                //$('input[name$=name]').css('backgroundColor', 'blue');
                //name属性包含name的              
                //$('input[name*=name]').css('backgroundColor', 'blue');
                //含有name和value属性的
                $('input[name][value]').css('backgroundColor', 'blue');
            });
            
        })
    </script>
    <style>
        div{
            width:300px;
            height:200px;
            background-color:orange;
            margin-bottom:20px;
        }
    </style>
</head>
<body>
    <input type="button" name="name" value="显示效果" id="btn" />
    <input type="text" name="1name1" value="" />
    <input type="text" name="2name2" value="" />
    <input type="text" name="name3" value="" />
    <input type="text" name="name4" value="" />
    <div id="dv1">

    </div>
    <div>

    </div>
    <div id="dv2">

    </div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: