jQuery选择器(在根目录下引用的js文件是jquery-3.3.1.js)

原创2018-12-29 22:09:2994
摘要:<!DOCTYPE html><html><head>  <meta charset="UTF-8">  <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

<!DOCTYPE html>

<html>


<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <meta http-equiv="X-UA-Compatible" content="ie=edge">

  <title>

jQuery选择器

</title>

  <script type="text/javascript" src="jquery-3.3.1.js"></script>

 <script type="text/javascript">

    $(document).ready(function() {

      $(':checked').parent().css('color', 'red'); //表单选择器,所有被选中的input元素

      $('label~input').css('background', 'pink'); //层级选择器,匹配prev元素后面所有的sibling:$('prev~sibling'),sibling同辈选择器

      $('span').css('font-size', '30px'); //基本选择器,$('element')标签选择器

      $('div:contains(jun)').css('background', 'blue'); //内容选择器,$(':contains(text)')匹配包含给定文本的元素

      $('input[type=button]').css('background', '#FF6B01'); //属性选择器,匹配给定属性是某个特定值的元素

      $('p:odd').css('background', '#ccc'); //顺序选择器,选择值为奇数的元素

    })

  </script>

  <script>

  </script>

</head>


<body>

  <form action="">

    输入框1<input type="text" name=""><br>

    输入框2<input type="text" name=""><br>

    输入框3<input type="text" name="" disabled><br>

    输入框4<input type="text" name=""><br>

    <select name="" id="">

      <option value="">1</option>

      <option selected>2</option>

      <option value="">3</option>

    </select>

    <br>

    爱好

    <label for=""><input type="checkbox">看书</label>

    <label for=""><input type="checkbox" checked>游泳</label>

    <label for=""><input type="checkbox">玩游戏</label>

  </form><br>

  <form>

    <label for="">姓名</label>

    <input type="text" name="">

    <button>按钮</button>

  </form><br>

  <span>php中文网</span><br>

  <div>jack</div><br>

  <label for="">2</label><input type="password" name="new1" id="man"><br>

  <p id="box">1</p>

  <p>2</p>

  <p>3</p>

  <p>4</p>

  <p>5</p>

  <p>6</p>

  <p>7</p>

  <p>8</p>

</body>


</html>


批改老师:天蓬老师批改时间:2018-12-30 13:28:24
老师总结:选择表单元素 , 有很多方式, 建议用推荐的伪类选择器, 少用类型选择器

发布手记

热门词条