Home > Web Front-end > JS Tutorial > body text

JavaScript has a problem in Android's WebView

高洛峰
Release: 2016-11-28 11:06:24
Original
1233 people have browsed it

I was troubled by a problem today. There is a page that runs fine on the browser (whether it is a mobile phone or a PC), but there is a problem through WebView. There are two worthy calculations that always go wrong. So I used alert to display this value, and found that it was much different from the result calculated on the browser. It was originally a positive number, but it became a negative number. After careful comparison, it was found that some of the numbers were erased, and these numbers were converted from strings through parseInt. The only difference between the erased values ​​and other normal numbers is that they all start with 0, such as "04903", while other values ​​are "90874". In this case, the reason is obvious. The JavaScript parseInt supported by WebView converts all strings starting with 0 to 0. Once the problem is solved, it will be easier. Just write a str2Int method to replace parseInt.


[javascript]
str2Int:function(str){
str = str.replace(/^0+/g, '');
if(str.length == 0){
return 0;
}
return parseInt(str);
}

str2Int:function(str){
      str = str.replace(/^0+/g, '');
                                                           
        }
              return parseInt(str);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template