如何在JavaScript中找到表单的accept-charset和enctype属性?

Javascript提供了document.acceptCharsetdocument.enctype来获取表单的accept-charsetenctype 。让我们单独讨论它们。

接受字符集

示例

在以下示例中,表单最初提供了一个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