3.18 老师帮忙看下 谢谢

来源:3-18 编程练习

1226122238

2018-11-17 21:48:11

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>数据类型转换</title>
</head>
<body>
<script>
var a="50px",b="px50",c="50px50",d="50.51"
document.write(a=(parseInt)(a)+"<br>")
document.write(b=(parseInt)(b)+"<br>")
document.write(c=(parseInt)(c)+"<br>")
document.write(d=(parseInt)(d)+"<br>")
document.write(typeof a)
document.write(typeof b)
document.write(typeof c)
document.write(typeof d)

    // 补充代码
</script>
</body>
</html>

为啥检测数据类型都是string字符串 最后一个50.51不应该是Number吗

写回答

2回答

好帮手慕夭夭

2018-11-19

你好同学 ,根据代码中 ,"50.51" 是字符串 . 使用引号包裹的都是字符串 ,如下都是字符串:

http://img.mukewang.com/climg/5bf214ed0001eb1603230099.jpg

祝学习愉快 ,望采纳 .

0

樱桃小胖子

2018-11-18

同学的代码书写错误,document.write(a=(parseInt)(a)+"<br>")正确的应该是parseInt(a),并且按照同学书写的代码,打印输出在页面上的是parseInt转换后的,但是在检测类型的时候,使用的仍然是没有用parseInt转换的变量,即在typeof检测类型的时候,使用的仍然是以下变量:

var a="50px",b="px50",c="50px50",d="50.51"

所以是string字符串,建议调整如下:

http://img.mukewang.com/climg/5bf0fe0a0001e43307740654.jpg

希望可以帮到你!

1
h226122238
h 所以50.51也是字符串吗?
h018-11-18
共1条回复

0 学习 · 36712 问题

查看课程