Home > Web Front-end > JS Tutorial > Introduction to the use of wildcards in jQuery's selectors_jquery

Introduction to the use of wildcards in jQuery's selectors_jquery

WBOY
Release: 2016-05-16 16:54:55
Original
1197 people have browsed it

1. Selector
(1) wildcard:

Copy code The code is as follows:

$("input[id^='code']");//All input tags whose id attribute starts with code
$("input[id$='code']");//The id attribute starts with code All input tags ending in
$("input[id*='code']"); //All input tags whose id attribute contains code

(2) Select
Copy code The code is as follows:
$("tbody tr:even"); //Select index All tr ​​tags with even numbers
$("tbody tr:odd"); //Select all tr ​​tags with odd indexes

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

Copy code The code is as follows:
jqueryObj.children("input").length;

(4) Get all tags under the child nodes of the tag with class main

Copy code The code is as follows:
$(".main > a");

(5) Select the label immediately adjacent to

Copy code The code is as follows:
jqueryObj.next("div");//Get the div immediately behind the jqueryObj tag , nextAll gets all

2. Filter

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

3. Event

Copy code The code is as follows:
/ /Handle keyboard operations on the text box
jqueryObj.keyup(function(event){
var keyCode = event.which;//Get the key value of the currently pressed keyboard, the Enter key is 13
}

4. Tool function

Copy code The code is as follows:
$('#someField').val($.trim($('#someField').val()));//Eliminate spaces, syntax: $.trim(value)

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