当前位置:网站首页>Transfer data to event object in wechat applet
Transfer data to event object in wechat applet
2022-07-06 18:01:00 【richest_ qi】
List of articles
Antecedents feed
to event Object delivery id
- to event Object delivery id(
id="btn"
):<button id="btn" bindtap="handleTap"> Click on me </button>
- from event Get in object id(
e.target.id
):handleTap(e){ console.log(e.target.id); }
to event Object passing custom attributes
- to event Object passing custom attributes (
data-type="confirm_btn"
):<button data-type="confirm_btn" bindtap="handleTap"> Click on me </button>
- from event Get custom attributes from object (
e.target.dataset.type
):handleTap(e){ console.log(e.target.dataset.type); }
Applet project
towards event Object delivery id
The main files involved in the code are :
- app.json
- pages/index/index.wxss
- pages/index/index.wxml
- pages/index/index.js
app.json
{
"pages": [
"pages/index/index"
],
"window": {
"navigationBarBackgroundColor": "#0149af",
"navigationBarTitleText": " Login Center ",
"navigationBarTextStyle": "white"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
pages/index/index.wxss
.container{
padding: 20rpx;
}
.container .title{
padding: 20rpx 0;
border-bottom: 1px solid #ddd;
font-weight: bold;
font-size: 32rpx;
}
.list{
margin: 40rpx auto 20rpx;
}
.item{
margin: 12rpx 0;
padding: 0 20rpx;
border: 1px solid #ddd;
border-radius: 6rpx;
}
.item input{
width: 100%;
height: 60rpx;
font-size: 28rpx;
}
button{
font-weight: normal;
font-size: 28rpx!important;
color: #fff;
background: #0149af;
}
pages/index/index.wxml
<view class="container">
<view class="title"> Sign in </view>
<view class="list">
<view class="item">
<input type="text" id="username" bindinput="handleInput" placeholder=" user name " />
</view>
<view class="item">
<input type="text" password id="password" bindinput="handleInput" placeholder=" password " />
</view>
</view>
<button size="mini"> Sign in </button>
</view>
pages/index/index.js
Page({
data:{
username:"",
password:""
},
handleInput(e){
const type = e.target.id;
this.setData({
[type]:e.detail.value
})
}
})
towards event Object passing custom attributes
The files involved in the code change are :
- pages/index/index.wxml
- pages/index/index.js
pages/index/index.wxml
<view class="container">
<view class="title"> Sign in </view>
<view class="list">
<view class="item">
<input type="text" data-type="username" bindinput="handleInput" placeholder=" user name " />
</view>
<view class="item">
<input type="text" password data-type="password" bindinput="handleInput" placeholder=" password " />
</view>
</view>
<button size="mini"> Sign in </button>
</view>
pages/index/index.js
Page({
data:{
username:"",
password:""
},
handleInput(e){
const type = e.target.dataset.type;
this.setData({
[type]:e.detail.value
})
}
})
Related links
Achieve animation effect through event binding
Event binding of wechat applet
边栏推荐
- The latest financial report release + tmall 618 double top, Nike energy leads the next 50 years
- 趣-关于undefined的问题
- Optimization of middle alignment of loading style of device player in easycvr electronic map
- Solid principle
- J'aimerais dire quelques mots de plus sur ce problème de communication...
- Olivetin can safely run shell commands on Web pages (Part 1)
- Unity粒子特效系列-闪星星的宝箱
- Open source and safe "song of ice and fire"
- C语言通过指针交换两个数
- Jerry's access to additional information on the dial [article]
猜你喜欢
Reppoints: advanced order of deformable convolution
面试突击62:group by 有哪些注意事项?
Interview assault 63: how to remove duplication in MySQL?
Four processes of program operation
std::true_type和std::false_type
Today in history: the mother of Google was born; Two Turing Award pioneers born on the same day
Basic configuration and use of spark
STM32 key state machine 2 - state simplification and long press function addition
Manifest of SAP ui5 framework json
sql语句优化,order by desc速度优化
随机推荐
RB157-ASEMI整流桥RB157
Jerry's watch deletes the existing dial file [chapter]
MySQL stored procedure
EasyCVR授权到期页面无法登录,该如何解决?
I want to say more about this communication failure
Alertmanager sends the alarm email and specifies it as the Alibaba mailbox of the company
C语言指针*p++、*(p++)、*++p、*(++p)、(*p)++、++(*p)对比实例
面试突击62:group by 有哪些注意事项?
Wechat applet obtains mobile number
面试突击62:group by 有哪些注意事项?
MySQL 8 sub database and table backup database shell script
FMT开源自驾仪 | FMT中间件:一种高实时的分布式日志模块Mlog
Jerry's watch reads the file through the file name [chapter]
d绑定函数
Pytest learning ----- detailed explanation of the request for interface automation test
Is it meaningful for 8-bit MCU to run RTOS?
Mysqlimport imports data files into the database
TCP packet sticking problem
High precision operation
[translation] principle analysis of X Window Manager (I)