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

How to determine whether a string contains a substring in jquery

coldplay.xixi
Release: 2023-01-04 09:36:29
Original
2696 people have browsed it

Jquery method to determine whether a string contains a substring: 1. Use the [test()] method to determine; 2. Use the [new RegExp('aa')] method; 3. Use [indexOf()] method to determine whether it contains characters.

How to determine whether a string contains a substring in jquery

The operating environment of this tutorial: ubuntu16 system, jquery1 version, Dell G3 computer. This method is suitable for all brands of computers.

Free learning recommendation: javascript learning tutorial

Jquery method to determine whether a string contains a substring:

1. Create a jq folder to place jquery, as well as two files include_test.html and include_test.js.

How to determine whether a string contains a substring in jquery

#2. Introduce jquery and the include_test.js script you created in the html header.

How to determine whether a string contains a substring in jquery

#3. First, we can use the test() method to determine whether it contains our own string.

How to determine whether a string contains a substring in jquery

4. You can also write new RegExp('aa') this way.

How to determine whether a string contains a substring in jquery

5. We can also use the indexOf() method to determine whether it contains characters. This indexOf() returns the position of the character. If not Character returns -1, as long as it is judged not to be -1, that is, >=0 exists.

How to determine whether a string contains a substring in jquery

#6. If you want to determine whether a certain string exists in the array, you can traverse and then use indexOf() to determine.

How to determine whether a string contains a substring in jquery

Related free learning recommendations: javascript(Video)

The above is the detailed content of How to determine whether a string contains a substring in jquery. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!