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

วิธีหา accept-charset และ enctype attribute ของ Form ใน JavaScript

form.acceptCharset และ form.enctype ให้ค่า attribute ตามลำดับ

Accept-Charset

<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

ค่าเริ่มต้นคือ "application/x-www-form-urlencoded" ไม่ต้องระบุใน HTML

<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