.toLowerCase不工作,更换功能? [英] .toLowerCase not working, replacement function?

查看:91
本文介绍了.toLowerCase不工作,更换功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在数字上使用它时, .toLowerCase 方法会给我一个错误。这就是我所拥有的:

The .toLowerCase method is giving me an error when I try to use it on numbers. This is what I have:

var ans = 334;
var temp = ans.toLowerCase();
alert(temp);

然后它给了我这个错误:

And then it gives me this error:

'undefined' is not a function (evaluating 'ans.toLowerCase()')

我不知道我错在哪里。我一直认为数字也可以被解析,结果没有变化(也许就是我填充的地方)。

I don't know where I got this wrong. I always thought that numbers can also be parsed, with no change in result (maybe that's where I stuffed up).

但如果这不是错误,有人可以写一个自定义 makeLowerCase 函数,使字符串小写,可能使用正则表达式或其他东西?

But if that's not the error, can someone write a custom makeLowerCase function, to make the string lower case, perhaps using regex or something?

推荐答案

.toLowerCase函数仅存在于字符串上。您可以在javascript中的任何内容上调用toString()来获取字符串表示。把这一切放在一起:

.toLowerCase function only exists on strings. You can call toString() on anything in javascript to get a string representation. Putting this all together:

var ans = 334;
var temp = ans.toString().toLowerCase();
alert(temp);

这篇关于.toLowerCase不工作,更换功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆