Table of Contents
Syntax: <input type="value">;
Home Web Front-end HTML Tutorial About HTML Input_html/css_WEB-ITnose

About HTML Input_html/css_WEB-ITnose

Jun 24, 2016 am 11:39 AM

Definition: The tag is used to collect user information. Input represents an input object in the Form form.

According to different type attribute values, input fields have many forms. Input fields can be text fields, checkboxes (single/checkboxes), masked text controls, radio buttons, (submit/reset) buttons, etc.

Example:

<form action="form_action.asp" method="get">  <p>First name: <input type="text" name="fname" /></p>  <p>Last name: <input type="text" name="lname" /></p>  <input type="submit" value="Submit" /></form>
Copy after login

Syntax: ;

Attribute value:

value 描述
button 定义可点击按钮(多数情况下,用于通过 JavaScript 启动脚本)。
checkbox 定义复选框。
file 定义输入字段和 "浏览"按钮,供文件上传
hidden 定义隐藏的输入字段。
image 定义图像形式的提交按钮。
password 定义密码字段。该字段中的字符被掩码。
radio 定义单选按钮。
reset 定义重置按钮。重置按钮会清除表单中的所有数据。
submit 定义提交按钮。提交按钮会把表单数据发送到服务器。
text 定义单行的输入字段,用户可在其中输入文本。默认宽度为 20 个字符。
Copy after login

具体介绍如下

  • ;
  • 定义可点击的按钮(标准的windows风格的按钮),但没有任何行为。button 类型常用于在用户点击按钮时启动 JavaScript 程序。因此,要让按钮跳转到某个页面上还需要加入写JavaScript代码。

    <form name="FormButton">  <input type="button" name="随便填" value="点击按钮" onclick="window.open('http://www.cnblogs.com/Loonger/')"> </form>  
    Copy after login

    效果:

  • ;
  • 定义复选框。复选框允许用户在一定数目的选择中选取一个或多个选项。多选框,常见于注册时选择爱好、性格、等信息。参数有name,value及特别参数checked(表示默认选择)其实最重要的还是value值,提交到处理页的也就是value。(附:name值可以不一样,但不推荐。)

    <form name="FormCheckbox">   <input type="checkbox" name="animal" value="dog" checked>This is a dog<br />   <input type="checkbox" name="animal" value="cat">This is a cat<br />   <input type="checkbox" name="animal" value="horse">This is a horse<br /> </form> /*name值可以不一样,但不推荐*/<form name="FormCheckbox">   <input type="checkbox" name="animal" value="dog" checked>This is a dog<br />   <input type="checkbox" name="animal" value="cat">This is a cat<br />   <input type="checkbox" name="animal" value="horse">This is a horse<br /> </form>
    Copy after login

    效果:

  • ;
  • 用于文件上传。该控件带有一个文本框和一个浏览按钮.当你在BBS、EMAIL中上传附件时一定少不了的控件。

    <form>  <input type="file" name="pic" accept="image/gif" /></form>
    Copy after login

    效果:

  • ;
  • 定义隐藏字段。隐藏字段对于用户是不可见的(如果一个非常重要的信息需要被提交到下一页,但又不能或者无法明示。 一句话,你在页面中是看不到hidden在哪里。最有用的是hidden的值。)隐藏字段通常会存储一个默认值,它们的值也可以由 JavaScript 进行修改。

    <form name="FormHidden"> your hidden info here:   <input type="hidden" name="hiddeninfo" value="Loong's Blog"> </form> <script>   alert("隐藏域的值是 "+document.FormHidden.hiddeninfo.value) </script> 
    Copy after login

    效果:

  • ;
  • 定义图像形式的提交按钮。

    <form>   <input type="image" src="submit.gif" alt="Submit" /></form> 
    Copy after login

  • ;
  • 定义密码字段。密码字段中的字符会被掩码(显示为星号或原点)。

    <form>  Email:<input type="text" name="email" /><br />  Password: <input type="password" name="pwd" maxlength="8" /><br /></form>
    Copy after login

    效果:

  • ;
  • 定义单选按钮,出现在多选一的页面设定中。参数同样有name,value及特别参数checked. 不同于checkbox的是,name值一定要相同,否则就不能多选一。当然提交到处理页的也还是value值。

    <form action="/example/html/form_action.asp" method="get">  <input type="radio" name="sex" value="male" /> Male<br />  <input type="radio" name="sex" value="female" /> Female<br /></form>/*下面是name值不同的一个例子,就不能实现多选一的效果了*/ <form>   <input type="radio" name="checkit1" value="a" checked><br>  <input type="radio" name="checkit2" value="b"><br>  <input type="radio" name="checkit3" value="c"><br> </form> 
    Copy after login

    效果:

  • ;
  • ;

    定义“提交”和“重置”两按钮,提交按钮用于向服务器发送表单数据。数据会发送到表单的 action 属性中指定的页面。重置按钮则起个快速清空所有填写内容的功能。

    <form>  Email: <input type="text" name="email" /><br />  Password: <input type="text" name="pin" maxlength="4" /><br />  <input type="reset" value="Reset" />  <input type="submit" value="Submit" /></form>
    Copy after login

    效果:

  • ;
  • 输入类型是text,这是我们见的最多也是使用最多的,比如登陆输入用户名,注册输入电话号码,电子邮件,家庭住址等等。当然这也是Input的默认类型。
    参数name:同样是表示的该文本输入框名称。
    参数size:输入框的长度大小。
    参数maxlength:输入框中允许输入字符的最大数。
    参数value:输入框中的默认值
    特殊参数readonly:表示该框中只能显示,不能添加修改

    <form action="/example/html/form_action.asp" method="get">  <p>Email: <input type="text" name="email" /></p>  <p>Password: <input type="text" name="pin" maxlength="18" /></p>  </form>
    Copy after login

    效果:见password部分。

     



    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

    The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

    Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

    HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

    What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

    The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

    What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

    The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

    What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

    The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

    What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

    The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

    The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

    HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

    Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

    WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

    See all articles