HTML DOM enctype 属性

定义和用法

enctype 属性可设置或返回用于编码表单内容的 MIME 类型。

如果表单没有 enctype 属性,那么当提交文本时的默认值是 "application/x-www-form-urlencoded"。

当 input type 是 "file" 时,值是 "multipart/form-data"。

语法

  1. formObject.encoding=encoding

实例

下面的例子可返回表单的编码类型:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function showEnctype()
  5. {
  6. var x=document.getElementById("myForm")
  7. alert(x.enctype)
  8. }
  9. </script>
  10. </head>
  11. <body>
  12.  
  13. <form id="myForm" enctype="application/x-www-form-urlencoded">
  14. Name: <input type="text" value="Mickey Mouse" />
  15. <input type="button" onclick="showEnctype()"
  16. value="Show enctype" />
  17. </form>
  18.  
  19. </body>
  20. </html>