if(string.Contains(string)). Is that possible?
I am trying to check if a string is contained in another string. Code behind is pretty straight forward. How can I do t开发者_运维百科hat in jquery?
function deleteRow(locName, locID) {
if(locName.Contains(locID)) {
alert("success");
}
}
Use String.prototype.indexOf
For example: (locName.indexOf(locID) > -1)
String.prototype.contains doesn't exist.
You can use the indexOf
method of the string. If you really want the convenience of having a contains
method, you could add one to String.prototype
:
String.prototype.contains = function(str) {
return this.indexOf(str) > -1;
};
alert("foobar".contains("oob")); // true
alert("foobar".contains("baz")); // false
you can use indexOf if the string is found returned result will be different from -1
function deleteRow(locName, locID) {
if(locName.indexOf(locID) != -1) {
alert("success");
}
}
I hope this helps
精彩评论