我想檢查一個字符串是否包含在另一個字符串中。後面的代碼非常簡單。我怎麼能在jQuery中做到這一點?if(string.Contains(string))。那可能嗎?
function deleteRow(locName, locID) {
if(locName.Contains(locID)) {
alert("success");
}
}
我想檢查一個字符串是否包含在另一個字符串中。後面的代碼非常簡單。我怎麼能在jQuery中做到這一點?if(string.Contains(string))。那可能嗎?
function deleteRow(locName, locID) {
if(locName.Contains(locID)) {
alert("success");
}
}
可以使用的indexOf如果串中發現返回的結果會有所不同,從-1
function deleteRow(locName, locID) {
if(locName.indexOf(locID) != -1) {
alert("success");
}
}
我希望這有助於
您可以使用字符串的方法indexOf
。如果你真的想有contains
方法的方便,你可以添加一個String.prototype
:
String.prototype.contains = function(str) {
return this.indexOf(str) > -1;
};
alert("foobar".contains("oob")); // true
alert("foobar".contains("baz")); // false
這是如何與.NET? – 2011-01-28 14:02:07
@FredrikMörk:固定的,它可能與他所指的代碼隱藏有關,因爲它是我看到的唯一.NET術語。 – BoltClock 2011-01-28 14:04:36