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

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

WBOY
WBOYOriginal
2016-06-13 13:52:101209browse

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


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

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