if sentence contains string
This question already has an answer here:
The method you're looking for is indexOf
(Documentation). Try the following
if (sentence.indexOf('Hello World') >= 0) {
alert('Yes');
} else {
alert('No');
}
试试这个:
if (sentence.indexOf("Hello World") != -1)
{
alert("Yes");
}
else
{
alert("No");
}
链接地址: http://www.djcxy.com/p/2050.html
上一篇: 'in'运算符在JavaScript中。 字符串比较
下一篇: 如果句子包含字符串