首页 > 编程语言 > 详细

JavaScript学习(二)基础知识

时间:2020-01-15 11:05:25      阅读:53      评论:0      收藏:0      [点我收藏+]

技术分享图片       技术分享图片

 

 

 变量类型:获取变量类型: alert(typeof  变量名);

技术分享图片

 

 

 undefined(未定义):1,没有定义过该变量 2,没有给该变量赋值

 类型转换:

1,string转换为int:parseInt(string类型变量);当变量内容不是数字时,转换为NaN(非数字)

判断变量是否为数字:

技术分享图片

 

 

 技术分享图片

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<script type="text/javascript">
    window.onload=function ()
    {
        
        var button1=document[getElementById](button1);
        button1.onclick=function()
        {
            var text1=document[getElementById](text1).value;
            var n=parseInt(text1);
            if(isNaN(n))
                             {
                             alert(n+不是数字);

                             }
                            else
                          alert(n+输入是数字);
        }
                 
    }
</script>
<body>
    <input type="text" id="text1">
    <input type=‘button‘ id="button1" value="判断">
</body>
</html>

2,string转换为float:parseFloat(string类型变量)

JavaScript学习(二)基础知识

原文:https://www.cnblogs.com/lq13035130506/p/12195484.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!