导航
×
   ❮   
HTML CSS JavaScript PHP Go Sass W3C Colors ECMS

HTML 参考手册

HTML 元素(功能排序) HTML 浏览器支持 HTML 属性 HTML 全局属性 HTML 事件 HTML 颜色 HTML 画布 HTML 音频/视频 HTML 字符集 HTML 文档类型 HTML URL 编码 HTML 语言代码 HTML 国家代码 HTTP 状态消息 HTTP 请求方法 PX-EM 转换 键盘快捷键

HTML 标签

<!--> <!DOCTYPE> <a> <abbr> <acronym> <address> <applet> <area> <article> <aside> <audio> <b> <base> <basefont> <bdi> <bdo> <big> <blockquote> <body> <br> <button> <canvas> <caption> <center> <cite> <code> <col> <colgroup> <data> <datalist> <dd> <del> <details> <dfn> <dialog> <dir> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <font> <footer> <form> <frame> <frameset> <h1> - <h6> <head> <header> <hr> <html> <i> <iframe> <img> <input> <ins> <kbd> <label> <legend> <li> <link> <main> <map> <mark> <meta> <meter> <nav> <noframes> <noscript> <object> <ol> <optgroup> <option> <output> <p> <param> <picture> <pre> <progress> <q> <rp> <rt> <ruby> <s> <samp> <script> <section> <select> <small> <source> <span> <strike> <strong> <style> <sub> <summary> <sup> <svg> <table> <tbody> <td> <template> <textarea> <tfoot> <th> <thead> <time> <title> <tr> <track> <tt> <u> <ul> <var> <video> <wbr>

HTML <input> 标签


实例

具有三个输入字段的HTML表单;两个文本字段和一个提交按钮:

<form action="/action_page.php">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname"><br><br>
  <input type="submit" value="提交">
</form>
亲自试一试 »

定义和用法

<input> 标签指定一个输入字段,用户可以在其中输入数据。

<input> 元素是最重要的表单元素。

根据类型属性的不同, <input> 元素可以以多种方式显示。

不同的输入类型如下所示,取决于 type 属性:

  • <input type="button">
  • <input type="checkbox">
  • <input type="color">
  • <input type="date">
  • <input type="datetime-local">
  • <input type="email">
  • <input type="file">
  • <input type="hidden">
  • <input type="image">
  • <input type="month">
  • <input type="number">
  • <input type="password">
  • <input type="radio">
  • <input type="range">
  • <input type="reset">
  • <input type="search">
  • <input type="submit">
  • <input type="tel">
  • <input type="text"> (默认值)
  • <input type="time">
  • <input type="url">
  • <input type="week">

查看 type 属性以查看每个 input 的类型!


提示和注释

提示: 你可以使用 <label> 元素来定义 input 元素的标注。 <input type="text">, <input type="checkbox">, <input type="radio">, <input type="file">, and <input type="password">.


浏览器支持

元素          
<input> Yes Yes Yes Yes Yes

属性

属性 描述
accept file_extension
audio/*
video/*
image/*
media_type
规定通过文件上传来提交的文件的类型。(只针对type="file")
alt text 定义图像输入的替代文本。 (只针对type="image")
autocomplete on
off
autocomplete 属性规定<input> 元素输入字段是否应该启用自动完成功能。
autofocus autofocus 属性规定当页面加载时<input> 元素应该自动获得焦点。
checked checked checked 属性规定在页面加载时应该被预先选定的 <input> 元素。 (只针对 type="checkbox" 或者 type="radio")
dirname inputname.dir Specifies that the text direction will be submitted
disabled disabled disabled 属性规定应该禁用的<input> 元素。
form form_id form 属性规定<input> 元素所属的一个或多个表单。
formaction URL 属性规定当表单提交时处理输入控件的文件的 URL。(只针对 type="submit" 和 type="image")
formenctype application/x-www-form-urlencoded
multipart/form-data
text/plain
属性规定当表单数据提交到服务器时如何编码(只适合 type="submit" 和 type="image")。
formmethod get
post
定义发送表单数据到 action URL 的 HTTP 方法。 (只适合 type="submit" 和 type="image")
formnovalidate formnovalidate formnovalidate 属性覆盖<form> 元素的 novalidate 属性。
formtarget _blank
_self
_parent
_top
framename
规定表示提交表单后在哪里显示接收到响应的名称或关键词。(只适合 type="submit" 和 type="image")
height pixels 规定 <input>元素的高度。(只针对type="image")
list datalist_id 属性引用 <datalist> 元素,其中包含<input> 元素的预定义选项。
max number
date
属性规定<input> 元素的最大值。
maxlength number 属性规定<input> 元素中允许的最大字符数。
min number
date
属性规定<input>元素的最小值。
minlength number Specifies the minimum number of characters required in an<input> element
multiple multiple 属性规定允许用户输入到<input> 元素的多个值。
name text name 属性规定<input> 元素的名称。
pattern regexp pattern 属性规定用于验证<input> 元素的值的正则表达式。
placeholder text placeholder 属性规定可描述输入<input> 字段预期值的简短的提示信息。
readonly readonly readonly 属性规定输入字段是只读的。
required required 属性规定必需在提交表单之前填写输入字段。
size number size 属性规定以字符数计的 <input> 元素的可见宽度。
src URL src 属性规定显示为提交按钮的图像的 URL。 (只针对type="image")
step number
any
step 属性规定<input> 元素的合法数字间隔。
type button
checkbox
color
date
datetime-local
email
file
hidden
image
month
number
password
radio
range
reset
search
submit
tel
text
time
url
week
type 属性规定要显示的 <input> 元素的类型。
value text 指定<input> 元素 value 的值。
width pixels width 属性规定 <input> 元素的宽度。 (只针对type="image")

全局属性

<input> 标签支持 HTML 中的全局属性


事件属性

<input> 标签支持 HTML 中的事件属性


相关页面

HTML 教程:

HTML DOM 参考手册:


默认CSS设置

None.


Copyright ©2020-2026 freew3c.com All Rights Reserved 提供的内容仅用于学习和测试,不保证内容的正确性。