基礎的小程序表單提交數據備份:
wxml:
<
form
bindsubmit
=
"formBindsubmit"
bindreset
=
"formReset"
>
<
view
style
=
"display:flex;"
>
<
label
>用戶名:</
label
>
<
input
name
=
"userName"
placeholder
=
"請輸入用戶名!"
/>
</
view
>
<
view
style
=
"display:flex;"
>
<
label
>密碼:</
label
>
<
input
name
=
"psw"
placeholder
=
"請輸入密碼!"
password
=
"true"
/>
</
view
>
<
view
style
=
"display:flex;margin-top:30px;"
>
<
button
style
=
"width:30%;"
formType
=
"submit"
>登陸</
button
>
<
button
style
=
"width:30%"
formType
=
"reset"
>重置</
button
>
</
view
>
</
form
>
<
view
>{{tip}}</
view
>
<
view
>{{userName}}</
view
>
<
view
>{{psw}}</
view
>
js
Page({
data:{
// text:"這是一個頁面"
tip:
''
,
userName:
''
,
psw:
''
},
formBindsubmit:
function
(e){
if
(e.detail.value.userName.length==0||e.detail.value.psw.length==0){
this
.setData({
tip:
'提示:用戶名和密碼不能爲空!'
,
userName:
''
,
psw:
''
})
}
else
{
this
.setData({
tip:
''
,
userName:
'用戶名:'
+e.detail.value.userName,
psw:
'密碼:'
+e.detail.value.psw
})
}
},
formReset:
function
(){
this
.setData({
tip:
''
,
userName:
''
,
psw:
''
})
}
})