1、获取form表单的数据
<form bindsubmit="formSubmit" bindreset="formReset">
<input type="text" value="{{username}}" name="username"/>
<input type="text" value="{{password}}" name="password"/>
<view class="btn-area">
<button form-type="submit">Submit</button>
<button form-type="reset">Reset</button>
</view>
</form>
Page({
formSubmit(e) {
console.log('form发生了submit事件,携带数据为:', e.detail.value)
},
formReset() {
console.log('form发生了reset事件')
}
})
2、获取文本框数据
<input type="text" bindinput="inputTitle" name="title" value="{{title}}" />
Page({
inputTitle: function (e) {
this.setData({
title: e.detail.value
})
}
)}
3、使用vant获取文本框值
<van-field
value="{{ username }}"
label="用户名"
placeholder="请输入用户名"
clearable
required
bind:blur ="userNameInput"
/>
userNameInput:function(e){
this.setData({
username: e.detail.value
})
}
4、bindinput与bindblur区别