TypeError t.replace is not a function错误

str = str.replace()

用replace报错了,错误信息为replace is not function ,发现这个函数只能用于字符串,当是数字的时候就会报此错误。

解决方法:
可先把内容强制转化为字符串,可用str.toString()来强制转换

str = str.toString().replace()

强制转换后,编译通过,调用没问题;
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/zch981964/article/details/131689696
今日推荐