var toLowerCase = function(str) {
if(String.prototype.toLowerCase) {
return str.toLowerCase();
}
let ret = ''
for(let i = 0; i < str.length; i++){
let code = str.charCodeAt(i)
if(code <= 90 && code>=65){
ret += String.fromCharCode(code + 32)
}else{
ret += str[i]
}
}
return ret
};
ASCII值大小寫之間相差32的性質
api 解釋
charAt() 方法可返回指定位置的字符。
"abcd".charAt(2); // "c"
charCodeAt() 方法可返回指定位置的字符的 Unicode 編碼。這個返回值是 0 - 65535 之間的整數。
"abcd".charCodeAt(2) // 99
fromCharCode() 可接受一個指定的 Unicode 值,然後返回一個字符串。
注意:該方法是 String 的靜態方法,字符串中的每個字符都由單獨的 Unicode 數字編碼指定。使用語法: String.fromCharCode()。