This article talks about jquery's selector. If you don't know about jquery's selector or are interested in jquery's selector, then let's take a look at this article. Okay, let's stop talking and get to the point. Bar
1.jQuery basic selector
###id
根据给定id匹配一个元素
.class
根据给定class匹配一个元素
element 根据给定元素名匹配元素
* 匹配所有的元素
selector1,selector2.,···,selectorN将每一个选择器匹配到的元素合并后一起返回
2. Hierarchical selector$(“parent child”)
选择parent中所有的child元素
$(“parent >child”)
选择parent中的子元素,而上面的是选择所有后代元素
$(“prev+next”)
选择紧跟在prev元素后的next元素(同辈)
注意:等价于 next()函数,即$(“.one”).next(“p”)
$(“prev~siblings”)
选择prev元素之后的所有siblings元素(同辈)
注意:等价于nextAll()函数,即$(“.one”).nextAll(“p”)
3. Filter selector
a.Basic filter selector:first
选择第一个元素 $(“p:first”)选择所有p元素中的第一个p元素,
与下面的first-child有区别
:last
选择最后一个元素,原理同上
:not(selector)
去除所有与给定选择器匹配的元素
:even
选择索引是偶数的所有元素
注意:索引从0开始
:odd
选择索引是奇数的所有元素
:eq(index)
选择索引等于index的元素
注意:index从0开始
:gt(index)
选择索引大于index的元素
:lt(index)
选择索引小于index的元素
:header
选择所有的标题元素,如h1,h2等等
:animated
选择正在执行动画的元素
:focus
选择当前获取焦点的元素
b. Content Filter
##:contains(text)
选择含有文本内容为text的元素
:empty
选择不包含子元素或者文本的元素
:has(selector)
选择含有选择器所匹配的元素的元素
:parent
选择含有子元素或者文本的元素(
这个比较绕)
c. Visibility Filter Selector:hidden
选择所有不可见的元素,
这个需要注意的是:它不仅包括样式属性display为“none”的元素,也包括文本隐藏域(<input type=“hidden” />)和visibility:hidden之类的元素
:visible
选择所有可见元素
d. Attribute filter selector【attribute】
选择拥有此属性的元素
【attribute = value】 选择属性值为value的元素
【attribute !=value】
选择属性值不为value的元素
【attribute^=value】
选择属性值以value开始的元素
【attribute $=value】
选择属性值以value结束的元素
【attribute *=value】
选择属性值含有value的元素
【attribute |=value】
选择属性等于给定字符串或者以该字符串为前缀(该字符串后跟一个连字符“-”)的元素
【attribute ~=value】
选择属性用空格分隔的值中包含一个给定值的元素
【attribute1】【attribute2】【attributeN】用属性选择器合并成一个复合属性选择器,满足多个条件,没选择一次,缩小一次范围
e. Child element filter selector:nth-child(index/even/odd/eq)
:eq(index)只会匹配一个元素,而:nth-child将为每一个父元素匹配子元素,
并且:nth-child(index)的index是从1开始的,:eq(index)是从0开始的
:first-child
选择每个父元素的第一个子元素,
:first只会返回单个元素,而:first-child将会为每个父元素匹配第一个子元素
:last-child
原理同上
:only-child 如果某个元素是它父元素中唯一的子元素,那么就会匹配
例如:$(“ul li:only-child”)在ul中选择有唯一子元素的li元素
f. Form object attribute filter selector
:enabled
选择所有可用元素
:disabled
选择所有不可用元素
:checked
选择所有被选中的元素,包括单选和复选
:selected
选择所有被选中的选项元素(下拉列表)
4. Form selector
:input
选择所有的表单元素
包括input、textarea、select、button元素
例如:$(“#form :input”)选择所有的表单元素 与 $(“#form input”)只获取input元素
:text
选择所有单行文本框
:password
选择所有密码框
:radio
选择所有单选框
:checkbox
选择所有多选框
:submit
选择所有提交按钮
:image
选择所有图像按钮
:reset
选择所有重置按钮
:button
选择所有按钮
:file
选择所有的上传域
:hidden
选择所有不可见元素
The above selectors can basically meet the needs of daily development and use. If you don’t know much about it, you can implement both sides yourself and it will be easy to master! Related recommendations: Detailed explanation of jQuery selector How to deal with special symbols
The above is the detailed content of jquery selector. For more information, please follow other related articles on the PHP Chinese website!

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
