/** index.js*/ var app = getApp() Page({ data: { /** * 页面配置 */ winWidth: 0, winHeight: 0, // tab切换 currentTab: 0, option1:[ {value:"1",contant:"A:xxxx"}, {value:"2",contant:"B:xxxx"}, {value:"3",contant:"C:xxxx"}, {value:"4",contant:"D:xxxx"} ], option2: [ { value: "1", contant: "A:xxxx" }, { value: "2", contant: "B:xxxx" }, { value: "3", contant: "C:xxxx" }, { value: "4", contant: "D:xxxx" } ], option3: [ { value: "1", contant: "A:xxxx" }, { value: "2", contant: "B:xxxx" }, { value: "3", contant: "C:xxxx" }, { value: "4", contant: "D:xxxx" } ], option1Value:0, option2Value:0, option3Value:0, }, onLoad: function() { swiperChange: function(e){ var that = this; if(that.data.currentTab==0){ that.setData({ option1Value : e.detail.value, currentTab: 1 }); }else if(that.data.currentTab==1){ that.setData({ option2Value : e.detail.value, currentTab: 2 }); }else if(that.data.currentTab==2){ that.setData({ option3Value : e.detail.value, currentTab: 3 }) } } }) 第一题 第二题 第三题 {{score}}
以上是我的代码,想实现页面中有三个题目,分别有四个不同分值的选项,用户选择后直接弹出结果,但是储存用户选择的选项的JSON数据是字符串,请问如何转换为数字类型?
雷雷
你存的时候是数字, parse出来就是数字...
现在你存的是字符串..
转换的话
+e.detail.value 就行