Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript
JavaScript
  1. โปรแกรม JavaScript ตรวจสอบปีอธิกสุรทิน

    เพื่อตรวจสอบว่าปีที่กำหนดเป็นปีอธิกสุรทินหรือไม่โดยใช้ JavaScript โค้ดมีดังนี้ตัวอย่าง<!DOCTYPE html> <html lang=en> <head> <meta charset=UTF-8 /> <meta name=viewport content=width=device-width, initial-scale=1.0 /> <title>Document</title> <style> body

  2. JavaScript array.toLocaleString() Function

    JavaScript array.toLocaleString() Function คืนค่าองค์ประกอบของ Array เป็นสตริงและคั่นด้วยสตริงเฉพาะ Locale เช่น คอมมา สามารถรับ Locale เป็นพารามิเตอร์เพื่อระบุ Language Tag ที่จะแปลงสตริงโค้ดต่อไปนี้เป็นตัวอย่าง array.toLocaleString() Functionตัวอย่าง<!DOCTYPE html> <html lang=en> <he

  3. JavaScript array.values()

    JavaScript array.values() คืนค่า Iterator Object ที่มีค่าทั้งหมดของ Array ที่กำหนดโค้ดต่อไปนี้เป็นตัวอย่าง array.values() Functionตัวอย่าง<!DOCTYPE html> <html lang=en> <head> <meta charset=UTF-8 /> <meta name=viewport content=width=device-width, initial-scale=1.0 /> &l

  4. JavaScript ArrayBuffer Object

    JavaScript ArrayBuffer Object ใช้เพื่อแทน Generic, Fixed-length Raw Binary Data Buffer เพื่อจัดการเนื้อหาของ ArrayBuffer Object เราต้องสร้าง DataView Object เนื่องจากเราไม่สามารถจัดการเนื้อหาโดยตรงได้ เราสามารถอ่านและเขียนได้ทั้งคู่โดยใช้ DataView Objectไวยากรณ์new ArrayBuffer(byteSize)พารามิเตอร์ b

  5. JavaScript Date Formats - รูปแบบวันที่ต่างๆ

    รูปแบบวันที่ใน JavaScript JavaScript Date object รองรับการสร้างและแปลงรูปแบบวันที่หลายแบบ ตั้งแต่ ISO 8601, RFC 2822, Unix Timestamp จนถึง Locale-specific formats ตัวอย่างโค้ดครบถ้วน { const date = new Date(iso); const valid = !isNaN(date.getTime()); log(`${iso.padEnd(30)}

  6. JavaScript ArrayBuffer.byteLength Property - ขนาดของ ArrayBuffer

    ArrayBuffer.prototype.byteLength คืออะไร? byteLength เป็น read-only property ของ ArrayBuffer ที่คืนค่าขนาดของ buffer ในหน่วย Bytes (ไบต์) กำหนดตอนสร้างและไม่สามารถเปลี่ยนแปลงได้ ตัวอย่างโค้ดครบถ้วน { log(`${name}:`); log(` view.byteLength = ${view.byteLength} bytes`); log

  7. JavaScript ArrayBuffer.isView() - ตรวจสอบ ArrayBuffer View

    ArrayBuffer.isView() คืออะไร? ArrayBuffer.isView(arg) เป็น static method ที่ตรวจสอบว่า argument ที่ส่งเข้ามาเป็น ArrayBuffer View (TypedArray หรือ DataView) หรือไม่ คืนค่า true / false ArrayBuffer Views ที่ตรวจสอบได้ TypedArrays: Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array

  8. JavaScript RegExp test() Method - ทดสอบการ Match ของ Regular Expression

    RegExp.prototype.test() คืออะไร? regex.test(string) ทดสอบว่ารูปแบบ (pattern) ตรงกับสตริงที่ให้มาหรือไม่ คืนค่า Boolean: true ถ้าตรง, false ถ้าไม่ตรง เร็วกว่า match() หรือ exec() เพราะไม่ต้องสร้าง array ผลลัพธ์ เหมาะสำหรับ Validation, Condition checking ถ้ามี flag g จะใช้ lastIndex (stateful)

  9. JavaScript RegExp toString() Method - แปลง Regular Expression เป็น String

    RegExp.prototype.toString() คืออะไร? คืนค่า String representation ของ Regular Expression object ในรูปแบบ Literal notation: /pattern/flags ใช้สำหรับ Debugging, Logging, Display pattern ให้ผู้ใช้เห็น คืนค่า string ที่เป็น valid RegExp literal เสมอ Escape special characters อัตโนมัติ ตัวอย่าง

  10. JavaScript Date.prototype[@@toPrimitive]() - แปลง Date เป็น Primitive Value

    Symbol.toPrimitive คืออะไร? Date.prototype[Symbol.toPrimitive] เป็นเมธอดพิเศษ (Well-known Symbol) ที่ JavaScript เรียกใช้เมื่อต้องการแปลง Date object ให้เป็น Primitive Value (string, number, หรือ default) ถูกเรียกอัตโนมัติเมื่อมีการ Type Coercion รับ parameter hint 3 ค่า: string, number, defau

  11. JavaScript ตรวจจับ Mobile Browser (User Agent Detection)

    การตรวจจับอุปกรณ์มือถือด้วย User Agent วิธีดั้งเดิมใช้ navigator.userAgent และ Regex เพื่อตรวจสอบว่าเป็นมือถือหรือไม่ แต่ ไม่แนะนำให้ใช้ใน Production เนื่องจาก User Agent สามารถปลอมแปลงได้ และรูปแบบเปลี่ยนแปลงตลอดเวลา ตัวอย่างโค้ด (วิธีเก่า - สำหรับการศึกษา) { // วิธีเก่า: User Agent Sniffi

  12. JavaScript - ตรวจจับปุ่มลูกศรที่กด (Detect Arrow Keys)

    การตรวจจับปุ่มลูกศรใน JavaScript ใช้ Event keydown หรือ keyup บน document หรือ window แล้วตรวจสอบ event.key (แนะนำ) หรือ event.keyCode (Legacy) ตัวอย่างโค้ดครบถ้วน (สมัยใหม่) <!DOCTYPE html> <html lang=th> <head> <meta charset=UTF-8 /> <meta name=viewport content=wid

  13. JavaScript Dialog Boxes - Alert, Confirm, Prompt

    Dialog Boxes แบบ Native ของ JavaScript JavaScript มี Dialog boxes ในตัว 3 แบบ ใช้สำหรับแจ้งเตือน ยืนยัน และรับข้อมูลจากผู้ใช้ Methodวัตถุประสงค์ปุ่มคืนค่า alert(message)แจ้งเตือนข้อมูล (One-way)OKundefined confirm(message)ยืนยันการกระทำ (Yes/No)OK, Canceltrue / false prompt(messa

  14. JavaScript WebAPI File.size Property - ตรวจสอบขนาดไฟล์

    File.size Property คืออะไร? File.size คืนค่าขนาดไฟล์ในหน่วย Bytes (ไบต์) เป็นตัวเลขจำนวนเต็ม (integer) Read-only property ค่า 0 = ไฟล์ว่างเปล่า ใช้สำหรับ validation ขนาดไฟล์ก่อนอัปโหลด รองรับในทุกเบราว์เซอร์สมัยใหม่ ตัวอย่างโค้ดครบถ้วน MAX_SIZE; const card = document.createEl

  15. JavaScript WebAPI File.type Property - ตรวจสอบประเภทไฟล์ (MIME Type)

    File.type Property คืออะไร? File.type เป็น property ของ File object (จาก <input type=file> หรือ Drag & Drop) ที่คืนค่า MIME Type ของไฟล์ เช่น image/jpeg, application/pdf, text/plain คืนค่าเป็น string (เช่น image/png) ถ้าไม่สามารถระบุได้ จะคืนค่า (empty string) ขึ้นอยู่กับ file extensi

  16. JavaScript ArrayBuffer.slice() Method - การสลายนำ ArrayBuffer

    ArrayBuffer.slice() คืออะไร? ArrayBuffer.prototype.slice(begin, end) สร้าง ArrayBuffer ใหม่ ที่เป็นสำเนาของข้อมูลบाइनะรี่จากตำแหน่ง begin (inclusive) ถึง end (exclusive) คล้ายกับ Array.slice() แต่ทำงานกับ binary data Syntax arrayBuffer.slice(begin[, end]) begin - index เริ่มต้น (0-based) รวมตัว

  17. JavaScript Basic Array Methods - เมธอดพื้นฐานของอาร์เรย์

    เมธอดพื้นฐาน 5 ตัวที่ต้องรู้ Methodคำอธิบายเปลี่ยน Array ต้นฉบับ?คืนค่า push(...items)เพิ่ม element ไปท้ายอาร์เรย์ใช่ (Mutate)ความยาวใหม่ pop()ลบ element ตัวสุดท้ายใช่Element ที่ลบ (หรือ undefined) unshift(...items)เพิ่ม element ไปหน้าอาร์เรย์ใช่ความยาวใหม่ shift()ลบ element ต

  18. JavaScript BOM Window Screen Object - คุณสมบัติหน้าจอ

    Window Screen Object คืออะไร? window.screen (หรือแค่ screen) เป็นออบเจ็กต์ของ Browser Object Model (BOM) ที่ให้ข้อมูลเกี่ยวกับหน้าจอของผู้ใช้ (Clients Screen) เช่น ความกว้าง ความสูง ความลึกสี เป็นต้น คุณสมบัติหลัก (Properties) Propertyคำอธิบายหน่วย screen.widthความกว้างหน้าจอทั้งหมดPixel

  19. ตัวอย่าง JavaScript Prompt Dialog Box

    Prompt Dialog Box คืออะไร? prompt() เป็น dialog box ในตัวของเบราว์เซอร์ (Native) ที่ใช้รับข้อมูลจากผู้ใช้ ผ่านช่องกรอกข้อความ มีปุ่ม OK และ Cancel ผู้ใช้กด OK → คืนค่าข้อความที่พิมพ์ (string) ผู้ใช้กด Cancel หรือปิดหน้าต่าง → คืนค่า null ผู้ใช้ไม่พิมพ์อะไรกด OK → คืนค่า (empty string) ตัว

  20. วิธีสร้างแกลเลอรีภาพแบบแท็บ (Tabbed Image Gallery) ด้วย CSS และ JavaScript

    ตัวอย่างโค้ด สร้างแกลเลอรีภาพที่คลิก thumbnail แล้วแสดงภาพขนาดใหญ่ใน Modal (Lightbox) พร้อมปุ่มปิดและรองรับ responsive 0 ? 1 : -1); }); </script> </body> </html> การทำงาน แสดง thumbnail เป็น Grid responsive (auto-fill) คลิก thumbnail → เปิด Modal แสดงภาพขนาดใหญ่ (โหล

Total 5941 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:152/298  20-คอมพิวเตอร์/Page Goto:1 146 147 148 149 150 151 152 153 154 155 156 157 158