1 determining whether an array type
Copy Code code as follows:
<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 determining whether a string type
Copy Code code as follows:
<script type= "Text/javascript" >
<! [cdata[
document.write (isstring (' Test '), ' <br/> ');
document.write (isstring), ' <br/> ';
function isstring (str) {
Return (typeof str== ' string ') &&str.constructor==String;
}
]]>
</script>
3 Determining whether a numeric type
Copy Code code as follows:
<script type= "Text/javascript" >
<! [cdata[
document.write (isnumber (' Test '), ' <br/> ');
document.write (Isnumber), ' <br/> ';
function Isnumber (obj) {
Return (typeof obj== ' number ') &&obj.constructor==Number;
}
]]>
</script>
4 Determine whether the date type
Copy Code code as follows:
<script type= "Text/javascript" >
<! [cdata[
document.write (IsDate (new Date), ' <br/> ');
document.write (isDate), ' <br/> ';
function IsDate (obj) {
Return (typeof obj== ' object ') &&obj.constructor==Date;
}
]]>
</script>
5 judge whether it is a function
Copy Code code as follows:
<script type= "Text/javascript" >
<! [cdata[
document.write (isfunction (function test () {}), ' <br/> ';
document.write (isfunction), ' <br/> ';
function Isfunction (obj) {
Return (typeof obj== ' function ') &&obj.constructor==Function;
}
]]>
</script>
6 Determine whether or not an object
Copy Code code as follows:
<script type= "Text/javascript" >
LineNum
<! [cdata[
document.write (IsObject (new Object), ' <br/> ');
document.write (IsObject), ' <br/> ';
function IsObject (obj) {
Return (typeof obj== ' object ') &&obj.constructor==Object;
}
]]>
</script>