一、基本选择器
id选择器:KaTeX parse error: Expected 'EOF', got '#' at position 3: (“#̲id名称”); 元素选择器:(“元素名称”);
类选择器:$(“.类名”);
通配符:*
多个选择器共用(并集)
代码演示:
二、层级选择器
ancestor descendant: 在给定的祖先元素下匹配所有的后代元素(儿子、孙子、重孙子)
parent > child : 在给定的父元素下匹配所有的子元素(儿子)
prev + next: 匹配所有紧接在 prev 元素后的 next 元素(紧挨着的,同桌)
prev ~ siblings: 匹配 prev 元素之后的所有 siblings 元素(兄弟)
代码演示:
三、基本过滤选择器
(′li′).first()等价于:(′li′).first()等价于:(“li:first”)
代码演示:
四、属性选择器
代码演示:
五、表单选择器
代码演示:
</head>
<body>
<input type="button" id="btn1" value="选择所有input元素" />
<input type="button" id="btn2" value="选择文本框" />
<br/>
<form>
<input type="text" /><br />
<input type="checkbox" /><br />
<input type="radio" /><br />
<input type="image" /><br />
<input type="file" /><br />
<input type="submit" />
<input type="reset" /><br />
<input type="password" /><br />
<input type="button" /><br />
<select><option/></select><br />
<textarea></textarea><br />
<button></button>
</form>
</body>