当前位置:网站首页>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
边栏推荐
- Smart street lamp based on stm32+ Huawei cloud IOT design
- 开源与安全的“冰与火之歌”
- The shell generates JSON arrays and inserts them into the database
- 微信小程序中给event对象传递数据
- The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
- Debug xv6
- 视频融合云平台EasyCVR增加多级分组,可灵活管理接入设备
- What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
- 重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
- Kill -9 system call used by PID to kill process
猜你喜欢
Why should Li Shufu personally take charge of building mobile phones?
F200——搭载基于模型设计的国产开源飞控系统无人机
Pourquoi Li shufu a - t - il construit son téléphone portable?
Alibaba brand data bank: introduction to the most complete data bank
C语言通过指针交换两个数
Unity particle special effects series - treasure chest of shining stars
J'aimerais dire quelques mots de plus sur ce problème de communication...
C语言指针*p++、*(p++)、*++p、*(++p)、(*p)++、++(*p)对比实例
Manifest of SAP ui5 framework json
基于STM32+华为云IOT设计的智能路灯
随机推荐
RepPoints:可形变卷积的进阶
李书福为何要亲自挂帅造手机?
std::true_type和std::false_type
The difference between parallelism and concurrency
10 advanced concepts that must be understood in learning SQL
Unity tips - draw aiming Center
MySQL 8 sub database and table backup database shell script
Jerry's access to additional information on the dial [article]
Principle and usage of extern
Binary search strategy
开源与安全的“冰与火之歌”
What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
Appium automated test scroll and drag_ and_ Drop slides according to element position
8位MCU跑RTOS有没有意义?
Heavy! Ant open source trusted privacy computing framework "argot", flexible assembly of mainstream technologies, developer friendly layered design
Summary of Android interview questions of Dachang in 2022 (I) (including answers)
面试突击62:group by 有哪些注意事项?
Pytorch extract middle layer features?
分布式不来点网关都说不过去
Olivetin can safely run shell commands on Web pages (Part 1)