微信小程序输入账号密码点击按钮登录事件示例代码
时间: 2023-02-08 09:44:15 浏览: 75
微信小程序登录事件示例代码如下:
1. 在页面的wxml文件中定义账号密码输入框和登录按钮:
```html
<view>
<input type="text" placeholder="请输入账号" bindinput="bindAccount" />
<input type="password" placeholder="请输入密码" bindinput="bindPassword" />
<button type="primary" bindtap="bindLogin">登录</button>
</view>
```
2. 在页面的js文件中编写绑定事件:
```javascript
Page({
data: {
account: '',
password: ''
},
bindAccount: function(e) {
this.setData({
account: e.detail.value
})
},
bindPassword: function(e) {
this.setData({
password: e.detail.value
})
},
bindLogin: function() {
let account = this.data.account;
let password = this.data.password;
console.log("account: " + account + " password: " + password);
if (account === '' || password === '') {
wx.showToast({
title: '账号密码不能为空',
icon: 'none'
});
return;
}
// 这里是请求服务器进行登录验证的代码
}
});
```
这里只是一个简单的示例代码,请根据你具体的需求进行修改
解释:
- 账号和密码输入框使用bindinput事件绑定获取输入的值
- 登录按钮使用bindtap绑定点击事件
- 在登录事件里面验证账号密码是否为空,不为空则进行服务器验证。
另外需要注意:这段代码是展示一个简单的思路,并不能直接运行,