导航
×
   ❮   
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 <button> 标签


实例

以下代码标记了一个按钮:

<button type="button">单击我!</button>
亲自试一试 »

下面有更多实例。


定义和用法

<button> 标签定义一个按钮。

<button> 元素内部,您可以放置内容,比如文本或图像。这是该元素与使用 <input> 元素创建的按钮之间的不同之处。

<button> 控件 与<input type="button"> 相比,提供了更为强大的功能和更丰富的内容。<button></button> 标签之间的所有内容都是按钮的内容,其中包括任何可接受的正文内容,比如文本或多媒体内容。例如,我们可以在按钮中包括一个图像和相关的文本,用它们在按钮中创建一个吸引人的标记图像。

唯一禁止使用的元素是图像映射,因为它对鼠标和键盘敏感的动作会干扰表单按钮的行为。

请始终为按钮规定 type 属性。Internet Explorer 的默认类型是 "button",而其他浏览器中(包括 W3C 规范)的默认值是 "submit"。


浏览器支持

元素          
<button> Yes Yes Yes Yes Yes

属性

属性 描述
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

覆盖 form 元素的 method 属性。

注释:该属性与 type="submit" 配合使用。

formnovalidate formnovalidate

覆盖 form 元素的 novalidate 属性。

注释:该属性与 type="submit" 配合使用。

formtarget _blank
_self
_parent
_top
framename

覆盖 form 元素的 target 属性。

注释:该属性与 type="submit" 配合使用。

name name 规定按钮的名称。
type button
reset
submit
规定按钮的类型。
value text 规定按钮的初始值。可由脚本进行修改。

全局属性

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


事件属性

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


更多实例

实例

使用CSS设置按钮样式:

   <!DOCTYPE html>
<html>
<head>
<style>
.button {
      border: none;
  color: white;
  padding: 15px 32px;
      text-align: center;
  text-decoration: none;
  display:     inline-block;
  font-size: 16px;
  margin: 4px 2px;
      cursor: pointer;
}

.button1 {background-color:     #4CAF50;} /* Green */
.button2 {background-color: #008CBA;} /* Blue */
   </style>
</head>
<body>

<button class="button     button1">绿色</button>
<button class="button button2">蓝色</button>

</body>
</html>
亲自试一试 »

实例

使用CSS设置按钮样式(具有悬停效果):

   <!DOCTYPE html>
<html>
<head>
<style>
.button {
      border: none;
  color: white;
  padding: 16px 32px;
      text-align: center;
  text-decoration: none;
  display:     inline-block;
  font-size: 16px;
  margin: 4px 2px;
      transition-duration: 0.4s;
  cursor: pointer;
}

.button1 {
      background-color: white; 
  color: black; 
  border: 2px     solid #4CAF50;
}

.button1:hover {
  background-color: #4CAF50;
      color: white;
}

.button2 {
  background-color: white; 
  color:     black; 
  border: 2px solid #008CBA;
}

.button2:hover {
      background-color: #008CBA;
  color: white;
}

</style>
</head>
<body>

   <button class="button button1">绿色</button>
<button class="button     button2">蓝色</button>
    
</body>
</html>
亲自试一试 »

相关页面

HTML DOM 参考手册: Button 对象

CSS 教程: Styling Buttons


默认CSS设置

None.


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