Posted in Javascript onDecember 11, 2013
1 判断是否为数组类型
<STRONG><script type="text/javascript"> //<![CDATA[ var a=[0]; document.write(isArray(a),'<br/>'); function isArray(obj){ return (typeof obj=='object')&&obj.constructor==Array; } //]]> </script></STRONG>
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"> linenum //<![CDATA[ document.write(isObject(new Object()),'<br/>'); document.write(isObject(10),'<br/>'); function isObject(obj){ return (typeof obj=='object')&&obj.constructor==Object; } //]]> </script>
判断javascript的数据类型(示例代码)
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@