Javascript提供了document.acceptCharset和document.enctype来获取表单的accept-charset和enctype 。让我们单独讨论它们。
在以下示例中,表单最初提供了一个accept-charset并使用DOM属性document.acceptCharset来显示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
在以下示例中,使用document.enctype DOM命令显示表单的enctype。无需在表单中提供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