1 判斷是否為陣列類型 複製程式碼 程式碼如下: //var a=[0]; document.write(isArray(a),''); function isArray(obj){ return (typeof obj=='object')&&obj.constructor==Array; } //]]> 2 判斷是否為字串型別 複製程式碼 程式碼如下: <BR>//<![CDATA[ <BR>document.write(isString('test'),'<br/>'); <BR>document. write(isString(10),'<br/>'); <BR>function isString(str){ <BR>return (typeof str=='string')&&str.constructor==String; <BR>} <BR>//]]> <BR> 3 判斷是否為數值類型複製代碼 程式碼如下: <BR>//<![CDATA[ <BR>document.write(isNumber('test'), '<br/>'); <BR>document.write(isNumber(10),'<br/>'); <BR>function isNumber(obj){ <BR>return (typeof obj=='number') &&obj.constructor==Number; <BR>} <BR>//]]> <BR> 4 判斷是否為日期類型 複製程式碼 程式碼如下: <BR>//<![CDATA[ <BR>document.write(isDate(new Date()),'<br/>'); <BR>document.write(isDate(10),'<br/>'); <BR>function isDate(obj) { <BR>return (typeof obj=='object')&&obj.constructor==Date; <BR>} <BR>//]]> <BR> 5判斷是否為函數複製程式碼 程式碼如下: <BR>//<![CDATA[ <BR>document.write(isFunction(function test(){}),'<br/>'); <BR>document.write(isFunction(10),' <br/>'); <BR>function isFunction(obj){ <BR>return (typeof obj=='function')&&obj.constructor==Function; <BR>} <BR>//]]> <BR> 6 判斷是否為物件複製程式碼 程式碼> <div class="codebody" id="code15595">linenum<BR>//<![CDATA[ <BR>document.write(isObject(new Object()),'<br/ >'); <BR>document.write(isObject(10),'<br/>'); <BR>function isObject(obj){ <BR>return (typeof obj=='object')&&obj.constructor= =Object; <BR>} <BR>//]]> <BR>