Home > Web Front-end > JS Tutorial > body text

Introducing the use of wildcards in jQuery selectors

巴扎黑
Release: 2017-06-20 16:48:05
Original
1766 people have browsed it

This article mainly introduces the wildcard in the selector of jQuery. Friends who need it can refer to

1. Selector
(1 ) Wildcard:

Copy code The code is as follows:


$("input[id^='code']");//id All input tags whose attributes start with code
$("input[id$='code']");//All input tags whose id attribute ends with code
$("input [id*='code']"); //All input tags whose id attribute contains code


(2) Select ## based on index

#Copy code The code is as follows:

$("tbody tr:even"); //Select all tr ​​tags with even numbers
$(" tbody tr:odd"); //Select all tr ​​tags with odd indexes

(3) Get the number of inputs of the next-level node of jqueryObj

Copy code The code is as follows:

jqueryObj.children("input").length;

(4) Obtain class as All tags under the child nodes of the main tag

Copy code The code is as follows:

$(".main > a ");

(5)Select the label immediately adjacent

Copy code The code is as follows:

jqueryObj.next("p");//Get the p immediately behind the jqueryObj tag, nextAll gets all

2. Filter

Copy code The code is as follows:

//not
$("#code input:not([id^='code'])");//id is The code tag does not contain all input tags whose id starts with code

##3.

Event

Copy code

The code is as follows:

//Process keyboard operations on the text box

jqueryObj.keyup(function(event){
var keyCode = event.which;//Get the current pressed The key value of the keyboard, the Enter key is 13
}


4. Tools

Function

Copy code

The code is as follows:

$('#someField').val($.trim($('#someField').val()));//Eliminate spaces, syntax: $.trim(value)


The above is the detailed content of Introducing the use of wildcards in jQuery selectors. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template