微信小程序组件解读和分析:七、button按钮
button按钮组件说明:
button,顾名思义,按钮,类似于html的button标签。我们可以设置按钮的属性,比如字体颜色大小,背景颜色等,可以给按钮绑定事件,用户点击时会触发事件。
button按钮组件示例代码运行效果如下:

下面是WXML代码:
|
1
2
3
4
5
|
<!--index.wxml--><view class="content"> <text class="con-text">怎么飞?点击【按钮】即飞</text> <button class="con-button">Fly</button></view> |
下面是JS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
|
Page({ data:{ }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 }, onReady:function(){ // 页面渲染完成 }, onShow:function(){ // 页面显示 }, onHide:function(){ // 页面隐藏 }, onUnload:function(){ // 页面关闭 }}) |
下面是WXSS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
|
.content{ padding-top: 20px;}.con-text{ display: block; padding-bottom: 10px;}.con-button{ margin-top: 10px; color: black; background-color: lightgreen} |

下面是WXML代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
|
<!--index.wxml--><view class="content"> <view class="con-top"> <text class="text-decoration">#按钮尺寸#</text> <text class="con-text">mini:</text> <button class="con-button" size="mini">Fly</button> <text class="con-text">default:</text> <button class="con-button" size="default">Fly</button> </view> <view class="con-bottom"> <text class="text-decoration">#按钮类型#</text> <text class="con-text">primary:</text> <button class="con-button" type="primary">Fly</button> <text class="con-text">default:</text> <button class="con-button" type="default">Fly</button> <text class="con-text">warn:</text> <button class="con-button" type="warn">Fly</button> </view></view> |
下面是JS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
|
Page({ data:{ }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 }, onReady:function(){ // 页面渲染完成 }, onShow:function(){ // 页面显示 }, onHide:function(){ // 页面隐藏 }, onUnload:function(){ // 页面关闭 }}) |
下面是WXSS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
.content{ padding-top: 20px; width: 90%; padding-left: 20px;}.con-text{ display: block; padding-bottom: 10px;}.con-button{ color: black; background-color: lightgreen; margin-bottom: 10px;}.con-bottom{ padding-top: 20px;}.con-top{ padding-bottom: 20px;}.text-decoration{ color: blue; display: block; text-align: center;} |

下面是WXML代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<!--index.wxml--><view class="content"> <view class="con-top"> <text class="text-decoration">#按钮是否镂空#</text> <text class="con-text">镂空:</text> <button class="con-button" plain>本宝宝的背景被镂空了</button> <text class="con-text">没镂空:</text> <button class="con-button">我没有被镂空唉</button> </view> <view> <text class="text-decoration">#按钮是否禁用#</text> <text class="con-text">禁用:</text> <button class="con-button" disabled>禁用</button> <text class="con-text">没禁用:</text> <button class="con-button">活跃</button> </view> <view class="con-bottom"> <text class="text-decoration">#按钮前是否带loading图标#</text> <text class="con-text">有loading:</text> <button class="con-button" loading>开车</button> <text class="con-text">无loading:</text> <button class="con-button">开车</button> </view></view> |
下面是JS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
|
Page({ data:{ }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 }, onReady:function(){ // 页面渲染完成 }, onShow:function(){ // 页面显示 }, onHide:function(){ // 页面隐藏 }, onUnload:function(){ // 页面关闭 }}) |
下面是WXSS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
.content{ padding-top: 20px; width: 90%; padding-left: 20px;}.con-text{ display: block; padding-bottom: 5px;}.con-button{ color: black; background-color: lightgreen; margin-bottom: 5px;}.con-bottom{ padding-top: 5px;}.con-top{ padding-bottom: 5px;}.text-decoration{ color: blue; display: block; text-align: center;} |

下面是WXML代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
|
<!--index.wxml--><view class="content"> <text class="text-decoration">#按钮前是否带loading图标#</text> <form class="formstyle" bindsubmit="formSubmit" bindreset="formReset"> <view class="shurustyle"> 输入: <input name="username" class="inputstyle" /> </view> <view class="buttonstyle"> <button form-type="reset" class="con-button" hover-class="hoverbutton">重置</button> <button form-type="submit" class="con-button" hover-class="hoverbutton">提交</button> </view> </form></view> |
下面是JS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
Page({ data:{ }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 }, onReady:function(){ // 页面渲染完成 }, onShow:function(){ // 页面显示 }, onHide:function(){ // 页面隐藏 }, onUnload:function(){ // 页面关闭 }, formSubmit:function(e){ console.log(e.detail.value); }, formReset:function(e){ console.log(e.detail.value); }}) |
下面是WXSS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
.content{ padding-top: 20px; width: 90%; padding-left: 20px;}.con-button{ color: black; background-color: lightgreen; margin-bottom: 5px;}.text-decoration{ color: blue; display: block; text-align: center; padding-bottom: 20px;}.buttonstyle{ display: flex; flex-direction: row; padding-top: 20px;}.inputstyle{ background-color: lightgray; width: 80%;}.shurustyle{ padding-left: 15%;}.hoverbutton{ background-color: lightgray;} |

下面是WXML代码:
|
1
2
3
4
5
6
|
<view class="content"> <view class="con-top"> <text class="text-decoration">#按钮点击样式改变和绑定事件#</text> <button class="con-button" hover-class="hoverclass" loading="{{isloading}}" bindtap="changeLoading">loading</button> </view></view> |
下面是JS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
Page({ data:{ isloading:true }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 }, onReady:function(){ // 页面渲染完成 }, onShow:function(){ // 页面显示 }, onHide:function(){ // 页面隐藏 }, onUnload:function(){ // 页面关闭 }, changeLoading:function(){ console.log("loading status:"+this.data.isloading); var loadingstatus=this.data.isloading; this.setData({ isloading:!loadingstatus }) }}) |
下面是WXSS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
|
.content{ padding-top: 20px; width: 90%; padding-left: 20px;}.con-button{ color: black; background-color: lightgreen; margin-top: 15px;}.text-decoration{ color: blue; display: block; text-align: center; font-family: "KaiTi"}.hoverclass{ background-color: orange; color: green; font-size: 25px;} |
button按钮的主要属性:
|
属性
|
类型
|
默认值
|
描述
|
| size | String | default | 表示按钮的大小,有两个值:default和mini |
| type | String | default | 表示按钮的样式类型,有三个值:default、primary和warn |
| plain | Boolean | false | 表示按钮是否镂空,即背景是否被抹去,不写该属性则为false,写上该属性则为true,也可写成plain=”false” |
| disabled | Boolean | false | 表示按钮是否被禁用,不写该属性则为false,写上该属性则为true,也可写成plain=”false” |
| loading | Boolean | false | 表示按钮名称前是否有loading图标,不写该属性则为false,写上该属性则为true,也可写成plain=”false” |
| form-type | String | 无 | 与form表单组件一起使用时,reset表示清空form表单内容事件,submit表示提交form表单内容事件,即有两个值:reset和submit |
| hover-class | String | button-hover | 表示按钮被点击时的样式,可以自定义一个css,然后将hover-class指向这个css |
微信小程序组件解读和分析:七、button按钮的更多相关文章
- 微信小程序组件解读和分析:六、progress进度条
progress进度条组件说明: 进度条,就是表示事情当前完成到什么地步了,可以让用户视觉上感知事情的执行.progress进度条是微信小程序的组件,和HTML5的进度条progress类似. pro ...
- 微信小程序组件解读和分析:五、text文本
text文本组件说明: text 文本就是微信小程序中显示出来的文本. text文本组件的示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 1 2 3 4 <v ...
- 微信小程序组件解读和分析:四、icon图标
icon图标组件说明: icon是一种图标格式,用于系统图标.软件图标等,这种图标扩展名为.icon..ico.常见的软件或windows桌面上的那些图标一般都是ICON格式的.在应用上面很多地方 ...
- 微信小程序组件解读和分析:十四、slider滑动选择器
slider滑动选择器组件说明: 滑动选择器. slider滑动选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 ...
- 微信小程序组件解读和分析:十、input输入框
input输入框组件说明: 本文介绍input 输入框的各种参数及特性. input输入框示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 0 ...
- 微信小程序组件解读和分析:八、checkbox复选项
checkbox复选项组件说明: checkbox是小程序表单组件中的一个组件,作用是在表单中引导用户做出选择. 要使用checkbox组件,还需要在同组中所有的checkbox标签外使用checkb ...
- 微信小程序组件解读和分析:一、view(视图容器 )
view组件说明: 视图容器 跟HTML代码中的DIV一样,可以包裹其他的组件,也可以被包裹在其他的组件内部.用起来比较自由随意,没有固定的结构. view组件的用法: 示例项目的wxml ...
- 微信小程序组件解读和分析:十五、switch 开关选择器
switch 开关选择器组件说明: switch,开关选择器.只能选择或者不选.这种属于表单控件或者查询条件控件. switch 开关选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯 ...
- 微信小程序组件解读和分析:十三、radio单选项目
radio单选项目组件说明: radio:单选项目. radio-group: 单项选择器,内部由多个<radio/>组成. radio单选项目示例代码运行效果如下: 下面是WXML代码: ...
随机推荐
- vmware10上安装mac os 10.9
来源地址:http://dtbuluo.com/blog/archives/350 序言: 前几天跟朋友开玩笑说,要不我们一起来学习一下swift编程语言吧~我们就抱着玩玩的态度,没有想过要做出什么优 ...
- 对ASP.NET MVC 的路由一点理解
这个东西,真搞不懂.看了网上的教程和文章,也不懂(也不清楚写那些文章的人自己是否真的懂).只好靠自己一顿乱摸索. 好比说,下面这个路由: //路由1 config.Routes.MapHttpRout ...
- 2016/2/25 1、<表单验证<form></form> 2、正则表达式 3、事件
1.<表单验证<form></form> (1).非空验证(去空格) (2).对比验证(跟一个值对比) (3).范围验证(根据一个范围进行判断) (4).固定格式验证:电 ...
- Django模板语言(一)
1,Django模板语言 1.1>基础语法:1.1.1,变量相关:{{ 变量名 }},1.1.2,逻辑相关{% ... %} 在Django模板语言中按此语法使用:{{ 变量名 }},当模板引擎 ...
- mysql工作原理(网络搜索整理的)
原文网址:Mysql 工作原理 原文网址:MySQL运行原理与基础架构 mysql基本用法原文网址:MySQL(一):基本原理 SQL 语句执行过程 数据库通常不会被直接使用,而是由其他编程语言通过S ...
- ubuntu查看文件的权限
查看linux文件的权限: 查看path路径下名为filename的文件或文件夹的权限: ls -l path/filename ls -l path/filename 查看path路径下的所有文件的 ...
- div+css通用兼容性代码整理
一.Div+css通用兼容性代码 你可以在css开头加入 *html{padding:0px} <style> *html{padding:0px} /* Clear Fix */ .cl ...
- Lightoj 1017 - Brush (III)
1017 - Brush (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Sam ...
- YTU 1098: The 3n + 1 problem
1098: The 3n + 1 problem 时间限制: 1 Sec 内存限制: 64 MB 提交: 368 解决: 148 题目描述 Consider the following algor ...
- 谈一谈以太坊虚拟机EVM的缺陷与不足
首先,EVM的设计初衷是什么?它为什么被设计成目前我们看的样子呢?根据以太坊官方提供的设计原理说明,EVM的设计目标主要针对以下方面: 简单性(Simplicity) 确定性(Determinism) ...