微信小程序-form表单-获取用户输入文本框的值

微信小程序-form表单-获取用户输入文本框的值

java 复制代码
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.password);
},
html 复制代码
<!--pages/login/login3.wxml-->
<input class="input" name="userName" placeholder="请输入用户名"
    bindinput ="userNameInput"/>
 
<input class="input" name="password" placeholder="请输入密码"
     bindinput="passWdInput" />
 
<button class="loginBtn" bindtap="loginBtnClick">登录</button>
php 复制代码
//登录函数
toLogin(e){
  //获取提交的用户名和密码用变量存储
  var userName=e.detail.value.userName;
  var userPwd=e.detail.value.userPwd;
  console.log("要提交给服务器的用户名和密码是",userName,userPwd);
},
html 复制代码
<!--定义form组件-->
<form bindsubmit="toLogin">
    <!--输入框区块-->
    <view id="inputView">
        <!--文本框-->
        <input type="text" placeholder="手机号/用户名" name="userName"></input>
        <!--密码框-->
        <input type="text" placeholder="密码" password name="userPwd"></input>
    </view>
    <!--按钮区域-->
    <view id="buttonView">
        <button form-type="submit">登录</button>
        <button>注册</button>
        <view>忘记密码</view>
    </view>
</form>
相关推荐
黄华SJ520it1 小时前
顶俏洗衣液模式制度开发介绍:S2B2C社交分销+多门店核销系统全解析
前端·数据库·小程序·零售·系统开发
北极糊的狐4 小时前
钉钉小程序报错data.formatTime is not a function是因为 axml 模板中不能直接调用 Page 内自定义方法!
java·小程序·钉钉
show4331 天前
多格式导出怎么做?2026免费小程序TXT/SRT实践
开发语言·小程序·c#
AI砖家1 天前
AI编程—微信小程序开发规范
微信小程序·小程序·notepad++·ai编程
show4332 天前
2026小程序端视频转文字技术对比:识别引擎精度实测
小程序·音视频
sam-zy2 天前
微信小程序+ESP8266+Arduino 开发智能插座,有本地OTA功能
微信小程序·小程序
A24207349302 天前
微信小程序开发:常用基础语法与指令详解
微信小程序·小程序·notepad++
黄华SJ520it2 天前
青蓝送水类型社交裂变小程序系统技术拆解
小程序·系统开发
weikecms3 天前
星巴克API接口,星巴克点餐接口开发
大数据·小程序
游戏开发爱好者83 天前
系统状态:专为iPhone和iPad设计的实时系统性能监控工具全面介绍
android·ios·小程序·uni-app·iphone·webview·ipad