like .Contains in jquery

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

in asp .net c# i use

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

i want to same thing in client side means in JQuery.Some thing like below.

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

There is any method to do this.Thanks.


使用String.indexOf() MDN Docs方法

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

You don't need jQuery for this. It can be achieved with simple pure JavaScript:

var aa = "aa bb";
if(aa.indexOf("aa") >= 0){
   //some task
}

The method indexOf will return the first index of the given substring in the string, or -1 if such substring does not exist.


C#'s implementation of .Contains is actually a wrapper on it's implementation of .IndexOf . Therefore you can create your own .Contains function in javascript like this:

String.prototype.Contains = function (s) {
    return this.indexOf(s) != -1;
}
链接地址: http://www.djcxy.com/p/2046.html

上一篇: 检查另一个字符串是否存在的最佳方法是什么?

下一篇: 像jQuery中包含.Contains