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

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

WBOY
Release: 2016-06-13 10:00:08
Original
1141 people have browsed it

用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
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