文章目录
-
- <button> 标签定义一个按钮,在它内部您可以放置文本或图像等内容,这是该元素与使用 <input> 元素创建的按钮之间的不同之处。 tips:请始终为 <button> 元素规定 type 属性。不同的浏览器对<button> 元素的 type 属性使用不同的默认值。 代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>button – 亿速云(yisu.com)</title> </head> <body> <button type="button" onclick="alert('Hello world!')">Click Me!</button> </body> </html>
- 属性 值 描述 autofocus autofocus 规定当页面加载时按钮应当自动地获得焦点。 disabled disabled 规定应该禁用该按钮。 form form_id 规定按钮属于一个或多个表单。 formaction URL 规定当提交表单时向何处发送表单数据。覆盖 form 元素的 action 属性。该属性与 type="submit" 配合使用。 formenctype application/x-www-form-urlencodedmultipart/form-datatext/plain 规定在向服务器发送表单数据之前如何对其进行编码。覆盖 form 元素的 enctype 属性。该属性与 type="submit" 配合使用。 formmethod getpost 规定用于发送表单数据的 HTTP 方法。覆盖 form 元素的 method 属性。该属性与 type="submit" 配合使用。 formnovalidate formnovalidate 如果使用该属性,则提交表单时不进行验证。覆盖 form 元素的 novalidate 属性。该属性与 type="submit" 配合使用。 formtarget _blank_self_parent_topframename 规定在何处打开 action URL。覆盖 form 元素的 target 属性。该属性与 type="submit" 配合使用。 name name 规定按钮的名称。 type buttonresetsubmit 规定按钮的类型。 value text 规定按钮的初始值。可由脚本进行修改。
- <input> 标签用于创建交互式控件,这类控件是基于 web 表单的,它可以接收用户的数据、信息。 主要代码: <input type="submit" value="提交"> <input type="reset" value="重置"> 表单代码如下: <!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>button – 亿速云(yisu.com)</title> </head> <body> <form action="example.htm" method="post"> 姓名: <input type="text" name="FirstName" value="张三丰"><br> 电话: <input type="text" name="LastName" value="123456"><br> <br> <input type="submit" value="提交"> <input type="reset" value="重置"> </form> </body> </html>
这篇文章主要介绍了HTML按钮代码如何写的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇HTML按钮代码如何写文章都会有所收获,下面我们一起来看看吧。
<button> 标签定义一个按钮,在它内部您可以放置文本或图像等内容,这是该元素与使用 <input> 元素创建的按钮之间的不同之处。
tips:请始终为 <button> 元素规定 type 属性。不同的浏览器对<button> 元素的 type 属性使用不同的默认值。
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>button - 亿速云(yisu.com)</title>
</head>
<body>
<button type="button" onclick="alert('Hello world!')">Click Me!</button>
</body>
</html>
| 属性 | 值 | 描述 |
|---|---|---|
| autofocus | autofocus | 规定当页面加载时按钮应当自动地获得焦点。 |
| disabled | disabled | 规定应该禁用该按钮。 |
| form | form_id | 规定按钮属于一个或多个表单。 |
| formaction | URL | 规定当提交表单时向何处发送表单数据。覆盖 form 元素的 action 属性。该属性与 type="submit" 配合使用。 |
| formenctype | application/x-www-form-urlencoded multipart/form-data text/plain |
规定在向服务器发送表单数据之前如何对其进行编码。覆盖 form 元素的 enctype 属性。该属性与 type="submit" 配合使用。 |
| formmethod | get post |
规定用于发送表单数据的 HTTP 方法。覆盖 form 元素的 method 属性。该属性与 type="submit" 配合使用。 |
| formnovalidate | formnovalidate | 如果使用该属性,则提交表单时不进行验证。覆盖 form 元素的 novalidate 属性。该属性与 type="submit" 配合使用。 |
| formtarget | _blank _self _parent _top framename |
规定在何处打开 action URL。覆盖 form 元素的 target 属性。该属性与 type="submit" 配合使用。 |
| name | name | 规定按钮的名称。 |
| type | button reset submit |
规定按钮的类型。 |
| value | text | 规定按钮的初始值。可由脚本进行修改。 |
<input> 标签用于创建交互式控件,这类控件是基于 web 表单的,它可以接收用户的数据、信息。
主要代码:
<input type="submit" value="提交">
<input type="reset" value="重置">
表单代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>button - 亿速云(yisu.com)</title>
</head>
<body>
<form action="example.htm" method="post">
姓名: <input type="text" name="FirstName" value="张三丰"><br>
电话: <input type="text" name="LastName" value="123456"><br>
<br>
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
</body>
</html>
发表回复