search
HomeWeb Front-endHTML TutorialHow to get the value of the input tag in HTML? Detailed explanation on the usage of input value

This article mainly talks about the usage and value of the value attribute of the HTML input tag, as well as the associated values ​​of the value attribute of the input tag. Let’s take a look at this article together

First let’s take a look at the usage of the input tag in HTML:

The value attribute is the specified value of the input element .

For different types of input elements, the usage of the value attribute is also different:

For "button", "reset", "submit" types - define the text on the button

For "text", "password", "hidden" types - define the initial (default) value of the input field

For "checkbox", "radio", "image" types - define the values ​​related to the input element value. This value is sent to the form's action URL.

Note: The value attribute is required for and .

Note: The value attribute does not apply to .

Having said so much, let’s take a look at an example:

A form with a predefined value for the value attribute:

<form action="demo_form.asp" method="get">
  请输入用户名: <input type="text" name="fname" value="Bill" /><br />
  第二次用户名: <input type="text" name="lname" value="Gates" /><br />
  <input type="submit" value="提交" />
</form>

The effect is shown in the figure:

How to get the value of the input tag in HTML? Detailed explanation on the usage of input value

The above picture is the result of the code, which is the defined form.

Now let’s take a look at the associated value:

Take the input box as an example, can each box be input? This content is the value associated with the input box. If you set a value attribute for it, then the value you set is its value, which will be displayed in the input box. Similarly, a radio button can also set a value, but this value is not displayed like an input box if you set it, but setting it means it has such a value, just like marking whether it is male or female. It may not be possible to tell whether it is a boy or a girl, but it can be marked.

Sometimes you need to adjust an input tag from one position to another. The value of the input after adjustment is the value of the value attribute in the input tag. If the way you modify the value does not modify the value attribute, then adjust The value you set will be lost.

<form> 
<input id="input" type="input" value=&#39;2&#39;></input> 
</form>

So if you have the above operation, please make sure that the way you modify the value changes the value attribute of the input, or use other methods to achieve the above operation, such as jQuery's clone method.

Another checkbox method for the input tag:

<form action="demo-form.php">
  <input type="checkbox" name="vehicle[]" value="Bike">我会PHP<br>
  <input type="checkbox" name="vehicle[]" value="Car">我会html<br>
  <input type="checkbox" name="vehicle[]" value="Boat">我会python<br>
  <input type="submit" value="提交">
</form>

The effect of the above code is as shown in the figure:

How to get the value of the input tag in HTML? Detailed explanation on the usage of input value

Okay , now this article is over, if you have any questions please leave a message below

[Editor’s recommendation]

in HTML How to write relative path in base tag? (Introduction to use included)

What is the usage of the src attribute of the HTML img tag? Analysis of specific usage methods (examples attached)

The above is the detailed content of How to get the value of the input tag in HTML? Detailed explanation on the usage of input value. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
HTML超文本标记语言--超在那里?(文档分析)HTML超文本标记语言--超在那里?(文档分析)Aug 02, 2022 pm 06:04 PM

本篇文章带大家了解一下HTML(超文本标记语言),介绍一下HTML的本质,HTML文档的结构、HTML文档的基本标签和图像标签、列表、表格标签、媒体元素、表单,希望对大家有所帮助!

laravel input隐藏域怎么实现laravel input隐藏域怎么实现Dec 12, 2022 am 10:07 AM

laravel input隐藏域的实现方法:1、找到并打开Blade模板文件;2、在Blade模板中使用method_field方法来创建隐藏域,其创建语法是“{{ method_field('DELETE') }}”。

vue3怎么封装input组件和统一表单数据vue3怎么封装input组件和统一表单数据May 12, 2023 pm 03:58 PM

准备工作用vuecreateexample创建项目,参数大概如下:用原生input原生的input,主要是value和change,数据在change的时候需要同步。App.tsx如下:import{ref}from&#39;vue&#39;;exportdefault{setup(){//username就是数据constusername=ref(&#39;张三&#39;);//输入框变化的时候,同步数据constonInput=;return()=>({

web前端笔试题库之HTML篇web前端笔试题库之HTML篇Apr 21, 2022 am 11:56 AM

总结了一些web前端面试(笔试)题分享给大家,本篇文章就先给大家分享HTML部分的笔试题(附答案),大家可以自己做做,看看能答对几个!

HTML5中画布标签是什么HTML5中画布标签是什么May 18, 2022 pm 04:55 PM

HTML5中画布标签是“<canvas>”。canvas标签用于图形的绘制,它只是一个矩形的图形容器,绘制图形必须通过脚本(通常是JavaScript)来完成;开发者可利用多种js方法来在canvas中绘制路径、盒、圆、字符以及添加图像等。

Vue文档中的input框绑定事件详解Vue文档中的input框绑定事件详解Jun 21, 2023 am 08:12 AM

Vue.js是一种轻量级的JavaScript框架,具有易用、高效和灵活的特点,是目前广受欢迎的前端框架之一。在Vue.js中,input框绑定事件是一个十分常见的需求,本文将详细介绍Vue文档中的input框绑定事件。一、基础概念在Vue.js中,input框绑定事件指的是将输入框的值绑定到Vue实例的数据对象中,从而实现输入和响应的双向绑定。在Vue.j

点击input框没有光标怎么办点击input框没有光标怎么办Nov 24, 2023 am 09:44 AM

点击input框没有光标的解决办法:1、确认输入框焦点;2、清除浏览器缓存;3、更新浏览器;4、使用JavaScript;​5、检查硬件设备;6、检查输入框属性;7、调试JavaScript代码;8、检查页面其他元素;9、考虑浏览器兼容性。

Vue文档中的input框回车事件和验证函数使用方法Vue文档中的input框回车事件和验证函数使用方法Jun 20, 2023 am 09:13 AM

Vue是一个流行的JavaScript前端框架,它的核心是响应式数据绑定和组件系统。在Vue的应用程序中,input框是最常用的UI元素之一。在用户输入文本时,我们希望可以监听回车事件,并且在提交前对输入内容进行验证。本篇文章将介绍Vue文档中的input框回车事件和验证函数使用方法。一、Vue中input框回车事件在Vue中监听input框的回车事件非常简

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!