发布网友 发布时间:2022-04-26 16:03
共1个回答
热心网友 时间:2022-04-24 08:55
首先用parseInt将01、001、0001转换成数字时,将radix设为10,返回并不是NaN(不是数字),而是1、1、1,可做实验,代码如下:
<html>
<head>
<title>无标题文档</title>
<script language=javascript>
function a() {
var str1;
str1="01";
document.write(parseInt(str1,10));
}
function b() {
var str2;
str2="001";
document.write(parseInt(str2,10));
}
function c() {
var str3;
str3="0001";
document.write(parseInt(str3,10));
}
</script>
</head>
<body>
<div align=center>
<script language=javascript>
a();
</script>
</div>
<br />
<div align=center>
<script language=javascript>
b();
</script>
</div>
<br />
<div align=center>
<script language=javascript>
c();
</script>
</div>
</body>
</html>
结果为:1 1 1
再就是,如果没有radix,则默认为10,如:
<html>
<head>
<title>无标题文档</title>
<script language=javascript>
function a() {
var str;
str="98";
document.write(parseInt(str,8));
}
</script>
</head>
<body>
<div align=center>
<script language=javascript>
a();
</script>
</div>
</script>
</div>
</body>
</html>
结果是:98,而不是NaN