有没有它们的例子?
答案 0 :(得分:2)
以下脚本在javascript中的字符串原型中添加了contains
的方法,同样您可以根据需要添加更多方法。
<强>用法强>
var myName = "ZainShaikh";
if (myName.contains("zain", true)) { // this condition will be true, because of ignorecase parameter
alert('yuppie, this is my name.');
}
else {
alert('awww, this is not my name.');
}
原型方法
String.prototype.contains = function(value, ignorecase) {
if (ignorecase) {
return (this.toLowerCase().indexOf(value.toString().toLowerCase()) != -1);
}
else {
return this.indexOf(value) != -1;
}
};
答案 1 :(得分:-2)