Javascript 如何编写一个java脚本,返回转换为小写的调用字符串值。函数(";ABCDE";);//return";abcde“;
需要编写代码,将java脚本中的ABCDE转换为ABCDE,而不使用to小写函数。编写一个函数,返回转换为的调用字符串值 小写//功能(“ABCDE”);//返回“abcde”真的吗Javascript 如何编写一个java脚本,返回转换为小写的调用字符串值。函数(";ABCDE";);//return";abcde“;,javascript,Javascript,需要编写代码,将java脚本中的ABCDE转换为ABCDE,而不使用to小写函数。编写一个函数,返回转换为的调用字符串值 小写//功能(“ABCDE”);//返回“abcde”真的吗 addEventListener('load',function(){ 函数lame(字符串){ 返回字符串.toLowerCase(); } log(lame(“这是一个lame函数”); });使用此方法转换 function convert(str) { var result = ' '; for
addEventListener('load',function(){
函数lame(字符串){
返回字符串.toLowerCase();
}
log(lame(“这是一个lame函数”);
});代码>使用此方法转换
function convert(str) {
var result = ' ';
for (var i = 0; i < str.length; i++) {
var code = str.charCodeAt(i) // check if it's within the range of capital letters
if (code > 64 && code < 91) { // if so, add a new character to the result string // of the character from our code, plus 32
result += String.fromCharCode(code + 32) } else { // otherwise, just add the current character
result += str.charAt(i) } }
return result;
}
函数转换(str){
var结果=“”;
对于(var i=0;i64&&code<91){//如果是这样,请在代码中字符的结果字符串//中添加一个新字符,再加上32
result+=String.fromCharCode(code+32)}else{//否则,只需添加当前字符即可
结果+=str.charAt(i)}
返回结果;
}
这可能很有帮助String.prototype.toLowerCase
发布一些您尝试过的代码。如果你仅仅要求别人为你写代码,你将不会在这个网站上得到良好的回应。此外,您应该阅读“如何创建一个最小、完整和可验证的示例”。也可以读“我该如何问一个好问题?”<代码>YourStringorVarthatisString.toLowerCase()代码>可能重复的