//测试js 忽略大小写的方法
<script>
String.prototype.equalsIgnoreCase = function(anotherString) {
if(this === anotherString){ //如果两者相同 否则判端两个的大小写是否为null
return true;
}
//因为 typeof(null) = object typeof(undefined) = undefined 实际上也是判端了这两个不为空
if(typeof(anotherString)==='string'){ //this!=null&&this!=undefined &&anotherString!=null&& anotherString!=undefined
return this.toLowerCase() == anotherString.toLowerCase(); //
}
return false;
}
//调用方式
console.log("1".equalsIgnoreCase("1")); // true
console.log("1".equalsIgnoreCase(1)); //false
console.log("测试AAA".equalsIgnoreCase("测试aaa")); // true
console.log("测试AAA".equalsIgnoreCase("测试AAA")); //true
</script>