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

เปลี่ยนรูปแบบวันที่/เวลาใน HTML5 ด้วย Custom Elements และ Shadow DOM

ใช้ Custom Elements เปลี่ยน Date Time Format

สามารถสร้าง Custom Element เพื่อ override รูปแบบวันที่ได้ โดยใช้ Shadow DOM

ตัวอย่าง Custom Element

<date-timeformatchange format="dd/mm/yyyy"></date-timeformatchange>

ข้อจำกัด: IE10 และเก่ากว่าไม่รองรับ Custom Elements เบราว์เซอร์รุ่นใหม่รองรับเต็มที่

ทางเลือกอื่น: ใช้ <input type="datetime-local"> ร่วมกับ JavaScript จัดรูปแบบ