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

How to use jquery api

小云云
Release: 2017-12-04 10:50:07
Original
1628 people have browsed it

In this article we will share with you the jquery api usage instructions, hoping to help everyone.

jQuery.inArray() function is used to search for a specified value in an array and return its index value. If the value does not exist in the array, -1 is returned.

This function belongs to the global jQuery object.

Syntax

jQuery 1.2 adds the static function.

jQuery.inArray( value, array [, fromIndex ] )

Parameter Parameter Description


value Any type for The value to look for.

array Array type specifies the array to be searched.

fromIndex Optional/Number type specifies to start searching from the specified index position of the array, the default is 0.

Return value

The return value of the jQuery.inArray() function is of type Number, which returns the index of the specified value in the array. If not found, -1 is returned.

If there are multiple identical values ​​in the array, the index of the first value found shall prevail.

Note: If you want to determine whether the specified value exists in the array, you need to determine whether the return value of the function is not equal to (or greater than) -1.

Example & Description

The jQuery sample code of jQuery.inArray() function is as follows:

//在当前页面内追加换行标签和指定的HTML内容
function w( html ){
document.body.innerHTML += "<br/>" + html;
}
var arr = [ 10, 25, 3, 0, -3 ];

w( $.inArray( 25, arr ) ); // 1
w( $.inArray( -3, arr ) ); // 4
w( $.inArray( 10, arr ) ); // 0

// 数组中没有99
w( $.inArray( 99, arr ) ); // -1
// 数组中有数字10,但是没有字符串"10"
w( $.inArray( "10", arr ) ); // -1
Copy after login

Run the code

5 0

The main purpose of users is to obtain useful information, not to click on ads. Therefore, this site will try its best to provide good content and separate advertisements from content to ensure that all advertisements will not affect the normal reading experience of users. Users click on ads based only on their personal wishes and interests.

The above content is about the usage instructions of jquery api, I hope it can help everyone.

Related recommendations:

Follow Jquery API to learn Jquery one selector_jquery

Follow JQuery API to learn Jquery two attributes_ jquery

Learn Jquery with JQuery API Part 3 Filtering_jquery

Learn Jquery with JQuery API Part 4 css_jquery

Jquery api cheat sheet sharing_jquery

The above is the detailed content of How to use jquery api. 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