表單對象選擇器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><!DOCTYPE html>
        <html>

        <head>
            <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
            <title></title>
            <link rel="stylesheet" href="choose.css" type="text/css">
            <style>
                input {
                    display: block;
                    margin: 10px;
                    padding: 10px;
                }
            </style>
            <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
        </head>

<body>
<h2>子元素篩選選擇器</h2>
<h3>enabled、disabled</h3>
<form>
    <input type="text" value="未設置disabled" />
    <input type="text" value="設置disabled" disabled="disabled" />
    <input type="text" value="未設置disabled" />
</form>

<script type="text/javascript">
    //查找所有input所有可用的(未被禁用的元素)input元素。
    $('input:enabled').css("border", "2px groove red");
</script>

<script type="text/javascript">
    //查找所有input所有不可用的(被禁用的元素)input元素。
    $('input:disabled').css("border", "2px groove blue");
</script>

<h3>checked、selected</h3>
<form>
    <input type="checkbox" checked="checked">
    <input type="checkbox">
    <input type="radio" checked>
    <input type="radio">

    <select name="garden" multiple="multiple">
        <option>碼農</option>
        <option selected="selected">前端之樂</option>
        <option>活生生的生活</option>
        <option selected="selected">博客園</option>
    </select>

</form>

<script type="text/javascript">
    //查找所有input所有勾選的元素(單選框,複選框)
    //移除input的checked屬性
    $('input:checked').removeAttr('checked')
</script>

<script type="text/javascript">
    //查找所有option元素中,有selected屬性被選中的選項
    //移除option的selected屬性
    $('option:selected').removeAttr('selected')
</script>

</body>

</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章