首页 新闻 会员 周边

微信小程序报错TypeError: res.charAt is not a function

0
[待解决问题]

错误提示:

thirdScriptError
res.charAt is not a function;at pages/cal/cal page click function
TypeError: res.charAt is not a function

具体就是:

if (res == 0 || res.charAt(res.length - 1) == '∞' || res.charAt(0) == '='){
var dot = res.charAt(res.length - 1);
res = num
if (dot == '.') {
res = '0.' + res;
dot=''
}
}
中的:var dot = res.charAt(res.length - 1);不正确
 
如果条件是:
if (res == 0 || res.charAt(res.length - 1) == '∞' || res.charAt(0) == '=')
时可以通过
 
如果是条件是:
if ((res == 0 || res.charAt(res.length - 1) == '∞' || res.charAt(0) == '=') && res.charAt(res.length - 1)),没法通过。
 
如果将上面蓝色的&&换成|| ,条件是:
if ((res == 0 || res.charAt(res.length - 1) == '∞' || res.charAt(0) == '=') || res.charAt(res.length - 1)),可以通过。
 
求解
feiquan的主页 feiquan | 菜鸟二级 | 园豆:214
提问于:2018-04-04 02:41
< >
分享
所有回答(1)
0

你这个是写在函数里面的吧,小程序中嵌套函数调用时要在前面加上this, 比如A函数中调用B函数,要写成this.B

河畔 | 园豆:738 (小虾三级) | 2018-04-04 10:54

试了,不行,不可以

这个res.charAt(res.length - 1)不是this的原因吧,这个res.charAt(字符处理函数)【java中的】是那种类似与数学函数那样的,不用加this吧

支持(0) 反对(0) feiquan | 园豆:214 (菜鸟二级) | 2018-04-04 18:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册