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
原文:http://happyliu.blog.51cto.com/501986/1547842