#### button
按鈕。
| 屬性名 | 類型 | 默認值 | 說明 | 生效時機 | 最低版本 |
| ---------------------- | ------- | ------------ | ---------------------------------------- | -------------------------- | ---------------------------------------- |
| size | String | default | 按鈕的大小 | | |
| type | String | default | 按鈕的樣式類型 | | |
| plain | Boolean | false | 按鈕是否鏤空,背景色透明 | | |
| disabled | Boolean | false | 是否禁用 | | |
| loading | Boolean | false | 名稱前是否帶 loading 圖標 | | |
| form-type | String | | 用于 `<form/>` 組件,點擊分別會觸發 `<form/>` 組件的 submit/reset 事件 | | |
| open-type | String | | 微信開放能力 | | [1.1.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| app-parameter | String | | 打開 APP 時,向 APP 傳遞的參數 | open-type="launchApp" | [1.9.5](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| hover-class | String | button-hover | 指定按鈕按下去的樣式類。當 `hover-class="none"` 時,沒有點擊態效果 | | |
| hover-stop-propagation | Boolean | false | 指定是否阻止本節點的祖先節點出現點擊態 | | [1.5.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| hover-start-time | Number | 20 | 按住后多久出現點擊態,單位毫秒 | | |
| hover-stay-time | Number | 70 | 手指松開后點擊態保留時間,單位毫秒 | | |
| bindgetuserinfo | Handler | | 用戶點擊該按鈕時,會返回獲取到的用戶信息,從返回參數的detail中獲取到的值同[wx.getUserInfo](https://mp.weixin.qq.com/debug/wxadoc/dev/api/open.html#wxgetuserinfoobject) | open-type="getUserInfo' | [1.3.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| lang | String | en | 指定返回用戶信息的語言,zh_CN 簡體中文,zh_TW 繁體中文,en 英文。 | open-type="getUserInfo" | [1.3.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| session-from | String | | 會話來源 | open-type="contact" | [1.4.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| send-message-title | String | 當前標題 | 會話內消息卡片標題 | open-type="contact" | [1.5.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| send-message-path | String | 當前分享路徑 | 會話內消息卡片點擊跳轉小程序路徑 | open-type="contact" | [1.5.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| send-message-img | String | 截圖 | 會話內消息卡片圖片 | open-type="contact" | [1.5.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| show-message-card | Boolean | false | 顯示會話內消息卡片 | open-type="contact" | [1.5.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| bindcontact | Handler | | 客服消息回調 | open-type="contact" | [1.5.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| bindgetphonenumber | Handler | | 獲取用戶手機號回調 | open-type="getphonenumber" | [1.2.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| binderrror | Handler | | 當使用開放能力時,發生錯誤的回調 | open-type="launchApp" | [1.9.5](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
- **注1:button-hover 默認為{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;}**
- **注2:bindgetphonenumber 從1.2.0 開始支持,但是在1.5.3以下版本中無法使用wx.canIUse進行檢測,建議使用基礎庫版本進行判斷。**
- **注3: 在bindgetphonenumber 等返回加密信息的回調中調用 wx.login 登錄,可能會刷新登錄態。此時服務器使用 code 換取的 sessionKey 不是加密時使用的 sessionKey,導致解密失敗。建議開發者提前進行 login;或者在回調中先使用 checkSession 進行登錄態檢查,避免 login 刷新登錄態。**
**size 有效值:**
| 值 | 說明 |
| ------- | ---- |
| default | |
| mini | |
**type 有效值:**
| 值 | 說明 |
| ------- | ---- |
| primary | |
| default | |
| warn | |
**form-type 有效值:**
| 值 | 說明 |
| ------ | ---- |
| submit | 提交表單 |
| reset | 重置表單 |
**open-type 有效值:**
| 值 | 說明 | 最低版本 |
| -------------- | ---------------------------------------- | ---------------------------------------- |
| contact | 打開客服會話 | [1.1.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| share | 觸發用戶轉發,使用前建議先閱讀[使用指引](https://mp.weixin.qq.com/debug/wxadoc/dev/api/share.html#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%BC%95) | [1.2.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| getUserInfo | 獲取用戶信息,可以從bindgetuserinfo回調中獲取到用戶信息 | [1.3.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| getPhoneNumber | 獲取用戶手機號,可以從bindgetphonenumber回調中獲取到用戶信息,[具體說明](https://mp.weixin.qq.com/debug/wxadoc/dev/api/getPhoneNumber.html) | [1.2.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
| launchApp | 打開APP,可以通過app-parameter屬性設定向APP傳的參數[具體說明](https://mp.weixin.qq.com/debug/wxadoc/dev/api/launchApp.html) | [1.9.5](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html) |
**示例代碼:**
```
/** wxss **/
/** 修改button默認的點擊態樣式類**/
.button-hover {
background-color: red;
}
/** 添加自定義button點擊態樣式類**/
.other-button-hover {
background-color: blue;
}
<button type="default" size="{{defaultSize}}" loading="{{loading}}" plain="{{plain}}"
disabled="{{disabled}}" bindtap="default" hover-class="other-button-hover"> default </button>
<button type="primary" size="{{primarySize}}" loading="{{loading}}" plain="{{plain}}"
disabled="{{disabled}}" bindtap="primary"> primary </button>
<button type="warn" size="{{warnSize}}" loading="{{loading}}" plain="{{plain}}"
disabled="{{disabled}}" bindtap="warn"> warn </button>
<button bindtap="setDisabled">點擊設置以上按鈕disabled屬性</button>
<button bindtap="setPlain">點擊設置以上按鈕plain屬性</button>
<button bindtap="setLoading">點擊設置以上按鈕loading屬性</button>
<button open-type="contact">進入客服會話</button>
var types = ['default', 'primary', 'warn']
var pageObject = {
data: {
defaultSize: 'default',
primarySize: 'default',
warnSize: 'default',
disabled: false,
plain: false,
loading: false
},
setDisabled: function(e) {
this.setData({
disabled: !this.data.disabled
})
},
setPlain: function(e) {
this.setData({
plain: !this.data.plain
})
},
setLoading: function(e) {
this.setData({
loading: !this.data.loading
})
}
}
for (var i = 0; i < types.length; ++i) {
(function(type) {
pageObject[type] = function(e) {
var key = type + 'Size'
var changedData = {}
changedData[key] =
this.data[key] === 'default' ? 'mini' : 'default'
this.setData(changedData)
}
})(types[i])
}
Page(pageObject)
```
:-: 
- 簡介
- 第一章 公眾號開發
- 使用微信JSSDK
- 接口權限配置
- 分享接口
- 隱藏按鈕項
- 微信支付
- 第二章 小程序開發
- 基礎知識
- 分包加載
- WXSS樣式表
- 配置
- app.json配置
- window
- tabBar
- page.json配置
- 邏輯層
- app.js
- 場景值
- page.js
- 初始化數據
- 生命周期函數
- 頁面相關事件處理函數
- 事件處理函數
- 頁面實例方法
- 路由
- 文件作用域
- 模塊化
- 視圖層
- 模板語法
- 列表渲染
- 條件渲染
- 模板
- 事件
- 引用
- WXS語法規范
- WXS數據類型
- WXS控制流程
- WXS基礎類庫
- 組件
- 視圖容器
- view
- scroll-view
- swiper
- movable-view
- cover-view
- 基礎組件
- icon
- text
- rich-text
- progress
- 表單組件
- button
- checkbox
- form
- input
- label
- picker
- picker-view
- radio
- slider
- switch
- textarea
- 導航組件
- navigator
- 媒體組件
- audio
- image
- video
- camera
- 地圖組件
- map
- 畫布組件
- canvas
- 開放能力
- web-view
- 自定義組件
- 組件模版和樣式
- Component
- 組件傳值
- 組件事件
- Behaviors
- 組件間關系
- 網絡請求
- wx.request
- 微信登錄
- 獲取 openid 和 unionid
- 獲取用戶信息
- 將 wx.request 封裝為 promise
- 上傳圖片接口封裝
- 數據存儲
- 存儲數據和讀取數據
- 獲取數據緩存信息
- 移除數據緩存
- 獲取用戶設置
- openSetting
- getSetting
- 第三章 小游戲開發
- 參考資料