Home Backend Development PHP Tutorial 用js检验一个字符串是否在另一个字符串中解决方案

用js检验一个字符串是否在另一个字符串中解决方案

Jun 13, 2016 am 10:00 AM
alert indexof quot script

用js检验一个字符串是否在另一个字符串中

JScript code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><script type="text/javascript">if ('15,10,12'.indexOf('15') > 0){    alert('YES!');}else{    alert('NO!');}</script>
Copy after login

输出NO!可15明明是包含在前面一个字符串中的,请问如何修改??

------解决方案--------------------
'15,10,12'.indexOf('15') != -1
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement line break in alert How to implement line break in alert Nov 07, 2023 am 10:19 AM

alert implements line breaks using the br tag.

What does script mean? What does script mean? Aug 29, 2023 pm 02:00 PM

Script means script or script. In film, television, drama and other art forms, script is used to describe the dialogue, actions and scenes of characters, as well as the development and structure of the story. Script writing requires certain skills and experience, and it should be vivid and powerful, capable of attracting the audience's attention and conveying the emotions and themes of the story. Scripts are particularly important in the film and television industries. They are the basis of creation and determine the storyline, character development and dialogue content of the film. Script is an important tool for artists to create and express themselves.

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

what is script what is script Oct 12, 2023 am 10:04 AM

In the field of computer science, "script" usually refers to a scripting language or script file. A scripting language is an interpreted programming language commonly used for tasks such as automation, batch processing, and rapid prototyping.

How to solve scripterror How to solve scripterror Oct 18, 2023 am 09:44 AM

Solutions to scripterror include checking syntax, file path, checking network connection, browser compatibility, using try-catch statements, using developer tools for debugging, updating browsers and JavaScript libraries, or seeking professional help. Detailed introduction: 1. Check for syntax errors: Script Error may be caused by syntax errors in JavaScript code. Use developer tools to check the code and fix syntax errors. Make sure that the brackets, quotation marks, semicolons, etc. in the code are correct. etc.

What to do if alert is garbled in javascript What to do if alert is garbled in javascript Feb 10, 2023 am 09:40 AM

Solution to garbled alert code in JavaScript: 1. Add "charset=utf-8"" to the <head> part of HTML; 2. Add "charset="gb2312" or "charset="utf-" to the <script> tag 8""; 3. Change the saving encoding of the js external script to utf8.

What are the differences between indexof and includes? What are the differences between indexof and includes? Nov 24, 2023 pm 01:20 PM

The differences are: 1. Different return value types; 2. Different accepted parameters; 3. Different ways of treating NaN; 4. Different ways of treating upper and lower case; 5. Different data types that can be used.

What is the use of indexof method in java What is the use of indexof method in java May 17, 2023 pm 02:28 PM

indexof method: Note: The indexOf method returns an integer value indicating the starting position of the substring within the String object. If the substring is not found, -1 is returned. publicclassIndexOf{publicstaticvoidmain(String[]args){Strings="Li Hong#王海#林奇#鲁综合#唐梅"; Stringq="#";//The string to be found Stringrr="*";// Non-existent string inti=0;for(intj=0;j

See all articles