JavaScript在Android的WebView中parseInt函数转换不正确
来源:才华咖 本文已影响2.04W人
来源:才华咖 本文已影响2.04W人
今天被一个问题困扰,有一个页面在浏览器(无论是手机还是PC)上运行良好,而通过WebView就出现了问题,有两个值得计算始终出错。于是就通过alert,把这个值显示出来,发现和浏览器上计算的结果差了很多,本来是正数,却变成了负数。仔细比对发现,其中一部分数字被抹掉了,这些数字都是通过parseInt由字符串转化而来的。而被抹掉的值,和其他正常的数字唯一区别是,它们都是以0开头的,比如“04903”,而其他值都是“90874”。如此,原因就很明显了,WebView支持的`JavaScript的parseInt把以0开头的字符串全部转为了0。问题找到了解决就比较容易了,自己写一个str2Int的方法,来代替parseInt就可以了。
复制代码 代码如下:
str2Int:function(str){
str = ace(/^0+/g, ');
if(th == 0){
return 0;
}
return parseInt(str);
}
英语满分作文:Reading-TheBestMeanstoAcquireknowledge
The relationship between theory and practice大学英语作文
关于javascript中encodeURI和decodeURI的使用方法
私家车的坏处The Disadvantages of Private Cars英语作文
Dreamweaver中JavaScript行为操作
jQuery中的read和JavaScript中的onload函数的区别在哪
Should Private Cars Be Encouraged in China高中英语作文
My Happy Times During Winter Vacation初中英语作文
A Lifeguard at Johns Beach Saved a Drowning Child,A Lifeguar英语作文
Dreamweaver中JavaScript行为操作使用方法
四级作文:Create a Conservation-Oriented Campus
英语阅读:VIT declines to acquire Ang Mo Kio property
有关JavaScript中的prototype.bind()方法介绍
Dreamweaver中JavaScript行为操作使用的总结
A Letter to Univsity Pesident about the Canteen Service on C
《The Prevalence of Western Holidays》英语四级作文
关于学个词Learn a Word 第560课:activist
构造函数在导数解证不等式中的应用
九年级《unit 6 I like music that I can dance to. Period2》评课稿
英语作文introduce a few favorite books
英语报纸解读:Data may disrupt a peculiar business
英语阅读:TheTwelveDancingPrincesses
指数函数与对数函数的转换
My Winter Vacation Plans初中英语作文
A Letter to the Editor of a Newspaper英语四级作文
Jolie drops battle over perfume named Shilohy英语作文
Traditions of Chinese New Year为题目的作文
八年级英语下册Unit 6 An old man tried to move a Mountain period one说课稿
六年级英语上册Unit2 New York is in the east of America说课稿
whats your plan for dragon boat festival英语作文
关于女性的英语作文:Inspiring women leading the way
World Day to Combat Desertification大学英语作文
JavaScript在Android的WebView中parseInt函数转换不正确
,javascript break和continue区别
javascript中setInterval的用法总结
关于Thieving Bird Apes Its Victims的英语作文范文
英语报纸解读:Data may disrupt a peculiar business大纲
Efforts Urged to Improve Womens Reproductive Health英语阅读
常规不一定正确
高中生优秀英语作文:Have a break away from electronics