1 判斷是否為陣列型別2 判斷是否為字串型別3 判斷是否為數值型別4 判斷是否為日期型別5 判斷是否為函數6 判斷是否為物件1 判斷是否為陣列型別 複製程式碼 程式碼如下: 程式碼如下: <BR>//<![CDATA[ <BR>var a=[0]; <BR>document.write(isArray(a),'<br/>'); <BR>function isArray(obj){ <BR>return (typeof obj=='object')&&obj.constructor==Array; <BR>} <BR>//]]> 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> //]]> 3 判斷是否為數值類型複製代碼 程式碼如下: <BR>//<![CDATA[ <BR>document.write(isNumber('test'),' <br/>'); <BR>document.write(isNumber(10),'<br/>'); <BR>function isNumber(obj){ <BR>return (typeof obj=='number')&&objumber .constructor==Number; <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>//]]> 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>//]]> 6 判斷是否為物件複製程式碼 程式碼 <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>