JQUERY(入口函数 选择器)
入口函数
$(document).ready(function(){ });可以简写为$(function(){})
选择器
基本选择器
元素选择器 $("p") 所有 <p> 元素 id选择器#id $("#lastname") id="lastname" 的元素
class选择器 .class $(".intro") 所有 class="intro" 的元素 查找所有元素$("*") 所有元素
组合选择器 $('span,#two'); //组合选择器,选择span元素和id为two的元素
选择当前元素 $(this) 选择当前的html元素
层次选择器 我们可以把文档中的所有的节点节点之间的关系,用传统的家族关系来描述,可以把文档树当作一个家谱,
那么节点与节点直接就会存在父子,兄弟,祖孙的关系了。
后代元素、子元素、相邻元素和兄弟元素
$('body>div').css('background','pink'); //选择body里面的div子元素
$('body div').css('background','yellow'); //选择body里面所有的div元素
$('.one+div').css('background','black'); //选择class为one的下一个兄弟元素
$('#two~div').css('background','grey'); //选择id为two的元素的后面所有的div兄弟元素。前提是具有相同的父元素
$('#two').siblings('div'):选取#two所有同辈的div元素,无论前后位置
过滤选择器
:first $("p:first") 第一个 <p> 元素
:last $("p:last") 最后一个 <p> 元素
:even $("tr:even") 所有偶数 <tr> 元素
:odd $("tr:odd") 所有奇数 <tr> 元素
:eq(index) $("ul li:eq(3)") 列表中的第四个元素(index 从 0 开始)
:gt(no) $("ul li:gt(3)") 列出 index 大于 3 的元素
:lt(no) $("ul li:lt(3)") 列出 index 小于 3 的元素
:header $(":header") 所有标题元素 <h1> - <h6>
:animated 所有正在执行动画的元素
:root html元素
:has(selector)匹配含有选择器所匹配的元素的元素
:contains(text) $("div:contains('W3School')") 包含指定字符串的所有元素
:hidden $("p:hidden") 所有隐藏的 <p> 元素
:visible $("table:visible") 所有可见的表格
[attribute] $("[href]") 所有带有 href 属性的元素
[attribute=value] $("[href='#']") 所有 href 属性的值等于 "#" 的元素
[attribute!=value] $("[href!='#']") 所有 href 属性的值不等于 "#" 的元素
[attribute$=value] $("[href$='.jpg']") 所有 href 属性的值包含以 ".jpg" 结尾的元素
表单选择器
:input $(":input") 所有 <input> 元素
:text $("input:text") 所有 type="text" 的 <input> 元素
:password $("input:password") 所有 type="password" 的 <input> 元素
:radio $("input:radio") 所有 type="radio" 的 <input> 元素
:checkbox $("input:checkbox") 所有 type="checkbox" 的 <input> 元素
:submit $("input:submit") 所有 type="submit" 的 <input> 元素
:reset $("input:reset") 所有 type="reset" 的 <input> 元素
:button $("input:button") 所有 type="button" 的 <input> 元素
:image $("input:image") 所有 type="image" 的 <input> 元素
:file $("input:file") 所有 type="file" 的 <input> 元素
:not(selector) $("input:not(:empty)") 所有不为空的 input 元素
:enabled $("input:enabled") 所有激活的 input 元素
:disabled $("input:disabled") 所有禁用的 input 元素
:selected $("input:selected") 所有被选取的 input 元素
:checked $("input:checked") 所有被选中的 input 元素
$(‘input:focus’) 选取当前被焦点的元素
:has(selector)
最新文章
- AfxBeginThread和AfxEndThread+内存泄露
- Android MVP模式 简单易懂的介绍方式
- TD数量不确定时如何让其宽度平均分布
- uestc poj2559 秋实大哥去打工
- 1.0.3-学习Opencv与MFC混合编程之---打开本地摄像头
- Angular2学习笔记2
- python之@property
- React-代码复用(mixin.hoc.render props)
- Blinn-Phong模型
- Cookie 简单设置使用
- BZOJ.4727.[POI2017]Turysta(哈密顿路径/回路 竞赛图)
- 20181013xlVba年级成绩报表
- go语言基础学习
- 持续集成(Continuous Integration)基本概念与实践
- touch修改文件时间戳
- 关于Spring父容器和SpringMvc子容器
- Android——编译release版签名系统
- win7-x64上MySql的初次安装
- [Linux]运维三十六计--腾讯两位大神的总结
- R语言进阶之4:数据整形(reshape)