1 ตรวจสอบว่าเป็นประเภทอาร์เรย์หรือไม่
2 ตรวจสอบว่าเป็นประเภทสตริง
3 ตรวจสอบว่าเป็นประเภทตัวเลขหรือไม่
4 ตรวจสอบว่าเป็นประเภทวันที่
5 ตรวจสอบว่าเป็นฟังก์ชันหรือไม่
6 ตรวจสอบว่าเป็นวัตถุหรือไม่
1 ตรวจสอบว่าเป็นประเภทอาร์เรย์หรือไม่
คัดลอกรหัสรหัสดังนี้:
<script type = "text/javascript">
// <!
var a = [0];
document.write (isarray (a), '<br/>');
ฟังก์ชั่น isarray (obj) {
return (typeof obj == 'object') && obj.constructor == array;
-
-
</script>
2 ตรวจสอบว่าเป็นประเภทสตริง
คัดลอกรหัสรหัสดังนี้:
<script type = "text/javascript">
// <!
document.write (isstring ('test'), '<br/>');
document.write (isstring (10), '<br/>');
ฟังก์ชั่น isstring (str) {
return (typeof str == 'string') && str.constructor == สตริง;
-
-
</script>
3 ตรวจสอบว่าเป็นประเภทตัวเลขหรือไม่
คัดลอกรหัสรหัสดังนี้:
<script type = "text/javascript">
// <!
document.write (isnumber ('ทดสอบ'), '<br/>');
document.write (isnumber (10), '<br/>');
ฟังก์ชั่น isnumber (obj) {
return (typeof obj == 'number') && obj.constructor == number;
-
-
</script>
4 ตรวจสอบว่าเป็นประเภทวันที่
คัดลอกรหัสรหัสดังนี้:
<script type = "text/javascript">
// <!
document.write (isdate (วันที่ใหม่ ()), '<br/>');
document.write (isdate (10), '<br/>');
ฟังก์ชั่น iSdate (obj) {
return (typeof obj == 'object') && obj.constructor == วันที่;
-
-
</script>
5 ตรวจสอบว่าเป็นฟังก์ชันหรือไม่
คัดลอกรหัสรหัสดังนี้:
<script type = "text/javascript">
// <!
document.write (isfunction (การทดสอบฟังก์ชัน () {}), '<br/>');
document.write (isfunction (10), '<br/>');
ฟังก์ชั่น isfunction (obj) {
return (typeof obj == 'function') && obj.constructor == ฟังก์ชั่น;
-
-
</script>
6 ตรวจสอบว่าเป็นวัตถุหรือไม่
คัดลอกรหัสรหัสดังนี้:
<script type = "text/javascript">
// <!
document.write (isobject (New Object ()), '<br/>');
document.write (isobject (10), '<br/>');
ฟังก์ชั่น isobject (obj) {
return (typeof obj == 'object') && obj.constructor == Object;
-
-
</script>