jQuery經常使用屬性過濾選擇器

經常使用屬性過濾選擇器javascript

用戶名:
密 碼:
性 別:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
        <title>經常使用屬性過濾選擇器</title>
    <script src="scripts/jquery-3.1.1.js" type="text/javascript"></script>
    <script type="text/javascript">
            $(function(){
                //選取全部包含type的元素的長度
               // alert($("[type]").length);
                //查找form下的而且包含type屬性的全部元素
                //alert($("form *[type]").length);
                //alert($("[value^='提交']").length);//2  以...開始
                //alert($("[value$='表單']").length);//3  以...結尾
               // alert($("[value*='提']").length);    //3  包含...的
               // alert($("input[name=sex]").length);
               // alert($("input[name!=sex]").length);
                //[] []多個屬性的判斷
                alert($("input[class=c1] [type=text]").length);
            });

    </script>
</head>
<body>
<form id="form" action="#" method="post">
    用戶名:<input id="name" class="c1" type="text" name="name"><br/>
    密 碼:<input id="password" class="c1" type="password" name="name"><br/>
    性 別:<input name="sex" type="radio" value="male" checked>男
    <input name="sex" type="radio" value="female">女<br/>
    <input type="submit" value="提交表單">
    <input type="submit" value="提交 表單">
    <input type="submit" value="提 交 表單">
    <input type="reset" value="重置"><br/>
    <button type="submit">提交</button>
    <button type="reset">重置</button>
</form>
</body>
</html>
相關文章
相關標籤/搜索