Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript
JavaScript
  1. วิธีวาดรูปวงรี (Oval) ใน HTML5 Canvas

    ใช้ context.scale(x, y) ยืดหรือบีบวงกลมให้กลายเป็นวงรี ตัวอย่าง <!DOCTYPE HTML> <html> <head></head> <body> <canvas id=newCanvas width=450 height=300></canvas> <script> var c = document.getElementById(newCanvas); var context = c

  2. วิธีใช้ Antialiasing ใน HTML5 Canvas drawImage()

    ตั้งค่าคุณภาพการ resampling ด้วย ctx.imageSmoothingQuality = low|medium|high เทคนิคลดขนาดภาพแบบขั้นตอน (step-down scaling) เพื่อคุณภาพดีกว่า: // off-screen canvas var c = document.createElement(canvas), ocx = c.getContext(2d); c.width = img.width * 0.5; c.height = img.height * 0.5; ocx.drawImage(img

  3. เล่นไฟล์วิดีโอจากฮาร์ดดิสก์ (Local) ด้วยแท็ก video ใน HTML5

    ใช้ <input type=file> ให้ผู้ใช้เลือกไฟล์ แล้วสร้าง Object URL ชี้ไปที่ไฟล์นั้น ขั้นตอน: change event: ยิงเมื่อผู้ใช้เลือกไฟล์ File object: เข้าถึงผ่าน input.files[0] Object URL: ใช้ URL.createObjectURL(file) สร้าง URL ชั่วคราว Set video.src: กำหนด Object URL ให้ video element รองรับรูปแบบ: M

  4. วิธีสตรีมไฟล์ .mp4 ขนาดใหญ่ใน HTML5

    เพื่อให้วิดีโอ MP4 เล่นขณะดาวน์โหลด (progressive streaming) ต้อง: เข้ารหัสวิดีโอให้ข้อมูล moov atom อยู่หน้า (fast start) - ใช้โปรแกรม mp4 FastStart หรือ HandBrake ตัวเลือก Web Optimized เว็บเซิร์ฟเวอร์ต้องไม่บีบอัดไฟล์ MP4 ซ้ำด้วย gzip/deflate (เพราะ MP4 บีบอัดแล้ว) ตรวจสอบ HTTP Response Headers ด

  5. วิธีระบุว่าองค์ประกอบควรตรวจสอบ Vर्तनीและไวยากรณ์หรือไม่ใน HTML (spellcheck)

    ใช้แอตทริบิวต์ spellcheck ตั้งค่า true หรือ false สำหรับ <input>, <textarea>, และองค์ประกอบที่ contenteditable หมายเหตุ: ไม่ทำงานกับ input type=password ตัวอย่าง <!DOCTYPE html> <html> <body> Subject : <input type=text name=sub spellcheck=true> <p>

  6. วิธีสร้าง Definition Lists ใน HTML5

    ใช้แท็ก <dl> สำหรับ definition list <dt> สำหรับ term <dd> สำหรับ description ตัวอย่าง <!DOCTYPE html> <html> <head> <title>HTML dl Tag</title> </head> <body> <dl> <dt>Definition List</dt> <dd&g

  7. ตรวจสอบว่าเนื้อหาขององค์ประกอบแก้ไขได้หรือไม่ใน HTML (contenteditable)

    ใช้แอตทริบิวต์ contenteditable ตั้งค่าเป็น true เพื่อให้ผู้ใช้แก้ไขเนื้อหาได้โดยตรงในเบราว์เซอร์ ตัวอย่าง <!DOCTYPE html> <html> <body> <p contenteditable=true>This content is editable. Try to edit it.</p> <p>This is a normal content. It wont edit.</p

  8. วิธีเพิ่ม Section ในเอกสาร HTML

    ใช้แท็ก <section> เพื่อจับกลุ่มเนื้อหาที่เกี่ยวข้องกันเป็นส่วน (section) ในเอกสาร HTML5 ตัวอย่าง <!DOCTYPE html> <html> <head> <title>HTML Section Tag</title> </head> <body> <section> <h1>Java</h1> <h3>

  9. JavaScript AES Encryption คืออะไร?

    AES (Advanced Encryption Standard) เป็นมาตรฐานการเข้ารหัสข้อมูล สามารถใช้ใน JavaScript ผ่านไลบรารี Forge ขั้นตอนการใช้งาน: ติดตั้ง NPM: npm install node-forge Minify เพื่อใช้ในโปรเจกต์: npm run minify ใช้ AES-CBC 128-bit encryption ciphers สร้าง key และ generate IV ตัวอย่าง: เข้ารหัสสตริงเพื่อเก็บ

  10. ถูกต้องหรือไม่ที่จะสมมติว่า Switch Statement ใน JavaScript ใช้ Strict Comparison?

    ใช่ครับ JavaScript switch statement ใช้ Strict Equality (===) ในการเปรียบเทียบ ไม่ทำ type coercion ตัวอย่างทดสอบ: switch(1) { case 1: alert(Switch comparison: Not Strict.); break; case 1: alert(Switch comparison: Strict.); break; default: alert(Default); } ผลลัพธ์จะเป็น Swi

  11. วิธีทำ Automated Unit Testing ด้วย JavaScript

    ใช้ Unit.js - cross-platform open-source unit testing framework ตัวอย่าง var example = Welcome; test.string(example) .isEqualTo(Welcome); โครงสร้าง test suite: demo(Welcome, function() { demo1(Welcome to the website, function() { var example = Welcome; test.string(example) .isEqual

  12. ใน JavaScript Inheritance: แยกความแตกต่างระหว่าง Object.create() และ new

    ทั้งสองวิธีทำงานต่างกันอย่างสิ้นเชิง: 1. Object.create() - สืบทอด prototype เท่านั้น: function SomeClass() { } SomeClass.prototype = Object.create(amitBaseClass.prototype); สร้าง prototype chain ใหม่ ไม่เรียก constructor ของ parent 2. new - เรียก constructor และสืบทอด instance ทั้งหมด: function Some

Total 5941 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:222/298  20-คอมพิวเตอร์/Page Goto:1 216 217 218 219 220 221 222 223 224 225 226 227 228