当前位置:网站首页>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 solution that flutterweb browser cannot be rolled back after refreshing
- Four processes of program operation
- QT中Model-View-Delegate委托代理机制用法介绍
- IP, subnet mask, gateway, default gateway
- 基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
- Selected technical experts from China Mobile, ant, SF, and Xingsheng will show you the guarantee of architecture stability
- Jerry's watch reads the file through the file name [chapter]
- Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
- Debug and run the first xv6 program
- Open source and safe "song of ice and fire"
猜你喜欢
队列的实现
Pytest learning ----- detailed explanation of the request for interface automation test
Spark accumulator and broadcast variables and beginners of sparksql
The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?
78 year old professor Huake has been chasing dreams for 40 years, and the domestic database reaches dreams to sprint for IPO
FlutterWeb浏览器刷新后无法回退的解决方案
STM32按键状态机2——状态简化与增加长按功能
Sqoop I have everything you want
node の SQLite
After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer
随机推荐
It doesn't make sense without a distributed gateway
Pytorch extract middle layer features?
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
Shell input a string of numbers to determine whether it is a mobile phone number
Codeforces Round #803 (Div. 2)
Compile and build, from the bottom to the top
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
Unity粒子特效系列-闪星星的宝箱
面试突击63:MySQL 中如何去重?
Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
李書福為何要親自掛帥造手機?
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
Jielizhi obtains the currently used dial information [chapter]
Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology
8位MCU跑RTOS有没有意义?
Hongmeng introduction and development environment construction
Getting started with pytest ----- test case pre post, firmware
The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
基于STM32+华为云IOT设计的智能路灯
Heavy! Ant open source trusted privacy computing framework "argot", flexible assembly of mainstream technologies, developer friendly layered design