Javascript ได้จัดเตรียม document.acceptCharset และ document.enctype เพื่อรับ ชุดอักขระที่ยอมรับ และ enctype ของแบบฟอร์ม มาคุยกันทีละคน
ยอมรับ-Charset
ตัวอย่าง
ในตัวอย่างต่อไปนี้ รูปแบบ ในขั้นต้นได้จัดเตรียม accept-charset และใช้คุณสมบัติ DOM document.acceptCharset ที่ ยอมรับชุดอักขระ ค่าจะแสดงตามที่แสดงในผลลัพธ์
<html>
<body>
<form id="form1" accept-charset="ISO-8800-7"></form>
<p id="char"></p>
<script>
var cha = document.getElementById("form1").acceptCharset;
document.getElementById("char").innerHTML = cha;
</script>
</body>
</html> ผลลัพธ์
ISO-8800-7
Enctype
ตัวอย่าง
ในตัวอย่างต่อไปนี้ enctype ของแบบฟอร์มจะแสดงโดยใช้ document.enctype คำสั่ง DOM ไม่จำเป็นต้องระบุค่าของ enctype เช่น ชื่อ เป้าหมาย ฯลฯ ในรูปแบบ ทุกรูปแบบจะมี enctype ในตัว .
<html>
<body>
<form id="form1" name="form" action="/action_page.php"></form>
<p id="type"></p>
<script>
var ty = document.getElementById("form1").enctype;
document.getElementById("type").innerHTML = ty;
</script>
</body>
</html> ผลลัพธ์
application/x-www-form-urlencoded