微信小程式使用時注意事項
小程式注意事項:
1、判斷語句需要在{{ }} 中去判斷 wx:if=”ture && false || ture&&true”
wx:if="{{(item.tips==1&&item.steps==3)||(item.tips==2&&item.steps==5)}}"
2、bindtap=”” 函式方法function ( ){ } 傳參
wxml:
<view bindtap="GetAction"data-action="father">
<imagesrc="../images/img1.jpg"mode="widthFix"></image>
<text>文字</text>
</view>
js:
letaction=e.currentTarget.dataset.action;
Console.log(action);
控制檯:
father
註釋:
使用第一種的方法e.target.dataset.action 會獲取當前點選的元素的action,則獲取圖片上的action,圖片上沒有action便取的是undefined;
使用第二種的方法e.currentTarget.dataset.action 會獲取有事件的那個元素,即view,所以獲得“father”
3、如何重新整理data:{ showHide:flase, } showhide的值
data:{
showHide:false,
},
onOffFun: function (e){
varthat=this;
that.setData({
showHide:true
})
},
4、微信小程式實現簡單input正則表示式驗證功能
checkshr:function(e){
//收貨人判斷
varregLowerCase=newRegExp('[a-z]','g');//判斷使用者輸入的是否為小寫字母
varregCapitalLetter=newRegExp('[A-Z]','g');//判斷使用者輸入的是否為大寫字母
varregNum=newRegExp('[0-9]','g');//判斷使用者輸入的是否為數字
varrsLowerCase=regLowerCase.exec(e.detail.value);
varrsCapitalLetter=regCapitalLetter.exec(e.detail.value);
varrsNum=regNum.exec(e.detail.value);
if(rsLowerCase){
this.setData({
result:'您輸入的是小寫字母'
})
}elseif(rsCapitalLetter){
this.setData({
result:'您輸入的是大寫字母'
})
}elseif(rsNum){
this.setData({
result:'您輸入的是數字'
})
}else{
this.setData({
result:''
})
}
},
如果你的才華還實現不了你的野心,那就靜下心來,埋頭苦幹。