微信小程序获取input框的值

html

<view class="itemView">用户名:
<input class="input" name="userName" placeholder="请输入用户名"
bindinput ="userNameInput"/>
</view>
<view class="itemView">密 码:
<input class="input" password placeholder="请输入密码"
bindinput="passWdInput" />
</view>
<view class="viewName" style="background-color:#fbf9fe">
<button class="loginBtn" bindtap="loginBtnClick">登录</button>
</view>

 

js

// pages/index/login.js
Page({
data: {
userName: '',
userPwd:""
},
//获取用户输入的用户名
userNameInput:function(e)
{
this.setData({
userName: e.detail.value
})
},
passWdInput:function(e)
{
this.setData({
userPwd: e.detail.value
})
},
//获取用户输入的密码
loginBtnClick: function (e) {
console.log("用户名:"+this.data.userName+" 密码:" +this.data.userPwd);
}
,
// 用户点击右上角分享
onShareAppMessage: function () {

}
})

posted @ 2018-05-18 14:48  Chanhxy  阅读(17840)  评论(0编辑  收藏  举报