首页 > Web开发 > 详细

js判断变量类型的方法

时间:2014-09-02 18:11:45      阅读:201      评论:0      收藏:0      [点我收藏+]

js判断变量类型的方法

1.使用typeof

2.使用Variables.Constructor


使用实例

<script type="text/javascript">
    function fun(msg)
    {
        
        //使用typeof判断
        if(typeof msg=="string")
        {
            alert("使用typeof判断:"+msg);
        }
        //使用constructor判断
        if(msg.constructor==String)
        {
            alert("使用constructor判断"+msg);
        }
    }
    fun("aa");
</script>


本文出自 “开心编程” 博客,请务必保留此出处http://happyliu.blog.51cto.com/501986/1547842

js判断变量类型的方法

原文:http://happyliu.blog.51cto.com/501986/1547842

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