javascript - 等效于 ASP 的 .Contains 方法

标签 javascript jquery string

<分区>

Possible Duplicate:
JavaScript: string contains
Jquery: How to see if string contains substring

在 ASP .NET C# 中我使用:

string aa = "aa bb";
if (aa.Contains("aa"))
   { 
       //Some task       
   }

我想在客户端使用 JQuery 中的相同方法。如下所示:

var aa = "aa bb";
if(aa. -----want help here){
}

有什么方法可以做到这一点吗?

最佳答案

使用 String.indexOf() MDN Docs方法

if( aa.indexOf('aa') != -1 ){
// do whatever
}

更新

从 ES6 开始,有一个 String.includes() MDN Docs所以你可以做

if( aa.includes('aa') ){
// do whatever
}

关于javascript - 等效于 ASP 的 .Contains 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8400140/

相关文章:

javascript - 检索属性和字符串值,该字符串采用带有属性的标签格式

javascript - Knockout 动态模板在 IE9 中不加载

java - 迭代一个字符串并获取某些值

c - 如果其中包含整数,如何获取c中字符串的长度

javascript - 使用 org-mode 在 emacs 中管理 firefox 选项卡

javascript - 使用 Node.JS 可以同时运行的 setTimeout() 方法的最大数量是多少

javascript - 当 Javascript 中的 POST ID 元素插入 PDO 时,数据库中没有结果

javascript - 在 asp.net 中将复选框选定的值插入文本框?

javascript - 使用 JQuery 从动态加载的图像中获取图像 src

java - 如何在android页面中显示长字符串?