Posted in Javascript onJanuary 15, 2014
1 判断是否为数组类型
2 判断是否为字符串类型
3 判断是否为数值类型
4 判断是否为日期类型
5 判断是否为函数
6 判断是否为对象
1 判断是否为数组类型
<script type="text/javascript"> //<![CDATA[ var a=[0]; document.write(isArray(a),'<br/>'); function isArray(obj){ return (typeof obj=='object')&&obj.constructor==Array; } //]]> </script>
2 判断是否为字符串类型
<script type="text/javascript"> //<![CDATA[ document.write(isString('test'),'<br/>'); document.write(isString(10),'<br/>'); function isString(str){ return (typeof str=='string')&&str.constructor==String; } //]]> </script>
3 判断是否为数值类型
<script type="text/javascript"> //<![CDATA[ document.write(isNumber('test'),'<br/>'); document.write(isNumber(10),'<br/>'); function isNumber(obj){ return (typeof obj=='number')&&obj.constructor==Number; } //]]> </script>
4 判断是否为日期类型
<script type="text/javascript"> //<![CDATA[ document.write(isDate(new Date()),'<br/>'); document.write(isDate(10),'<br/>'); function isDate(obj){ return (typeof obj=='object')&&obj.constructor==Date; } //]]> </script>
5 判断是否为函数
<script type="text/javascript"> //<![CDATA[ document.write(isFunction(function test(){}),'<br/>'); document.write(isFunction(10),'<br/>'); function isFunction(obj){ return (typeof obj=='function')&&obj.constructor==Function; } //]]> </script>
6 判断是否为对象
<script type="text/javascript"> //<![CDATA[ document.write(isObject(new Object()),'<br/>'); document.write(isObject(10),'<br/>'); function isObject(obj){ return (typeof obj=='object')&&obj.constructor==Object; } //]]> </script>
js判断数据类型如判断是否为数组是否为字符串等等
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@