分享者:山水之间,来自原文地址
//index.xml
<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>{{userName}}</view>
<view>{{psw}}</view>
<toast duration="2000" hidden="{{toastHidden}}" bindchange="toastBindChange">用户名或密码不能为空!</toast>
//index.js
Page({
data:{
// text:"这是一个页面"
toastHidden:true,
userName:'',
psw:''
},
formBindsubmit:function(e){
if(e.detail.value.userName.length==0||e.detail.value.psw.length==0){
this.setData({
toastHidden:!this.data.toastHidden
})
}else{
this.setData({
tip:'',
userName:'用户名:'+e.detail.value.userName,
psw:'密码:'+e.detail.value.psw
})
}
},
formReset:function(){
this.setData({
userName:'',
psw:''
})
},
toastBindChange:function(){
this.setData({
toastHidden:!this.data.toastHidden
})
}
})
二:单选框
//index.wxml
<view class="item">
<p>单选</p>
<block wx:for="{{box}}" wx:for-item="box" wx:for-index="index">
<view wx:if="{{choose==index}}">
<view bindtap="choose" data-index="{{index}}" class="box_choose box">{{box.name}}</view>
</view>
<view wx:else="{{choose==index}}">
<view bindtap="choose" data-index="{{index}}" class="box">{{box.name}}</view>
</view>
</block>