jQuery # jQuery选择器

一、基本选择器

1. 元素选择器

选择所有的 <p> 元素

$("p")

2. ID选择器

选择 id 为 demo 的元素

$("#demo")

3. class类选择器

选择所有 class 为 test 的元素

$(".test")

 

二、实例

描述

代码

查找 ID 以 demo_ 开头的div $("div[id^='demo_']")
查找 ID 以 6 结尾的div $("div[id$='6']")
选取当前HTML元素 $(this)
选取 class 为 demo 的 <p> 元素 $("p.demo")
选取第一个 <p> 元素 $("p:first")
选取第一个 <ul> 元素的第一个 <li> 元素 $("ul li:first")
选取每个 <ul> 元素的第一个 <li> 元素 $("ul li:first-child")
选取带有 width 属性的元素 $("[width]")
选取所有 height 属性值等于 “100px” 的 <input> 元素 $("input[height='100px']")
选取所有 type = "button" 的 <input> 元素 和 <button> 元素 $(":button")
选取所有偶数位置的 <tr> 元素 $("tr:even")
选取所有奇数位置的 <tr> 元素 $("tr:odd")

猜你喜欢

转载自blog.csdn.net/qq_38134242/article/details/114137927