, the tags is the content of the button, including any acceptable body content, such as text or multimedia content. For example, we can include an image and associated text in a button and use them to create an attractive markup image in the button."/> , the tags is the content of the button, including any acceptable body content, such as text or multimedia content. For example, we can include an image and associated text in a button and use them to create an attractive markup image in the button.">
search
HomeWeb Front-endHTML TutorialThe difference and precautions between button and input type=button

The tags is the content of the button, including any acceptable body content, such as text or multimedia content. For example, we can include an image and associated text in a button and use them to create an attractive markup image in the button.
The only prohibited element is the image map, as its mouse and keyboard-sensitive actions interfere with the behavior of the form buttons.
Always specify the type attribute for buttons. The default type in Internet Explorer is "button", while the default in other browsers (including the W3C specification) is "submit".

Browser support

All major browsers support the , while other browsers will submit the content of the value attribute. Please use input elements in HTML forms to create buttons.

Notes

When using the value through $('#customBtn').val()
In IE When used in this way under (IE kernel), the value obtained is "button", not "test". Under non-IE, the value obtained is "test". Attend the first sentence marked in red above.
This should be distinguished from .
Through these two methods, $('#customBtn').val(), $('#customBtn').attr('value') obtains the value in different browsers, as follows:

The difference and precautions between button and input type=button

You can verify this by testing the following code

<html> 
<head> 
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/> 
<scripttype="text/javascript"src="jquery-1.4.4.min.js"></script> 
<scripttype="text/javascript"> 
$(function(){ 
$(&#39;#test1&#39;).click(function(){ 
alert($(&#39;#customBtn&#39;).attr(&#39;value&#39;)); 
}); 
$(&#39;#test2&#39;).click(function(){ 
alert($(&#39;#customBtn&#39;).val()); 
}); 
}); 
</script> 
</head> 
<body> 
<buttonid="customBtn"value="test">&#x6309;&#x94AE;</button> 
<inputtype="button"id="test1"value="getattr"/> 
<inputtype="button"id="test2"value="getval"/> 
</body> 
</html>

2. Inadvertently put the

<html> 
<body> 
<formaction=""> 
<button>button</button> 
<inputtype="submit"value="inputsubmit"/> 
<inputtype="button"value="inputbutton"/> 
</form> 
</body> 
</html>

The above is the detailed content of The difference and precautions between button and input type=button. 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怎么设置button大小及颜色html怎么设置button大小及颜色Mar 05, 2021 pm 05:16 PM

在html中,可以使用width和height属性来设置button元素的大小,使用background-color属性来设置button元素的颜色,具体语法为“button{width:宽度值;height:高度值;background-color: 颜色值;}”。

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()=>({

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框的回车事件非常简

jquery中input是什么元素jquery中input是什么元素Jun 06, 2023 pm 02:18 PM

jquery中input是选择器选取表单元素,其作用是:1、input用于搜集用户信息,根据不同的type属性值,输入字段拥有很多种形式,输入字段可以是文本字段、复选框、掩码后的文本控件、单选按钮、按钮等等;2、input标签可定义输入域的开始,在其中用户可输入数据;3、使用input标签来进行定义,其中包括文本字段、多选列表、可单击的图像和提交按钮等。

html5 input 禁止输入怎么实现html5 input 禁止输入怎么实现Feb 03, 2023 am 10:02 AM

html5 input禁止输入的实现方法:1、通过readonly规定输入字段为只读可复制;2、通过disabled实现被禁用的input元素可复制,但不能接收焦点;3、通过控制input的max length为0实现;4、通过“οnfοcus="this.blur();"”实现不能输入文本即可。

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
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools