小程序:四種默認(rèn)彈框

wxml代碼

<view class="container" class="zn-uploadimg">

<button type="primary"bindtap="showok">消息提示框</button>

<button type="primary"bindtap="modalcnt">模態(tài)彈窗</button>

<button type="primary"bindtap="actioncnt">操作菜單</button>

</view>

1,消息提示——wx.showToast(OBJECT)


var? app = getApp()

Page({

showok:function(){

wx.showToast({

title:'成功',

icon:'success',

duration:2000

})

}

})

2,模態(tài)彈窗——wx.showModal(OBJECT)


var app = getApp()

Page({

modalcnt:function(){

wx.showModal({

title: '提示',

content: '這是一個(gè)模態(tài)彈窗',

success: function(res) {

if (res.confirm) {

console.log('用戶點(diǎn)擊確定')

} else if (res.cancel) {

console.log('用戶點(diǎn)擊取消')

}

}

})

}

})

3.操作菜單——wx.showActionSheet(OBJECT)


var app = getApp()?

Page({

actioncnt:function(){

wx.showActionSheet({

itemList: ['A', 'B', 'C'],

success: function(res) {

console.log(res.tapIndex)

},

fail: function(res) {

console.log(res.errMsg)

}

})

}

})

4.指定modal彈出


wxml:

<!--show.wxml-->

<view class="container" class="zn-uploadimg">

<button type="primary"bindtap="modalinput">modal有輸入框</button>

</view>

<modal hidden="{{hiddenmodalput}}" title="請(qǐng)輸入驗(yàn)證碼" confirm-text="提交" cancel-text="重置" bindcancel="cancel" bindconfirm="confirm">

? ? <input type='text'placeholder="請(qǐng)輸入內(nèi)容" auto-focus/>

</modal>

js代碼

//show.js

//獲取應(yīng)用實(shí)例?

var app = getApp()?

Page({

data:{

? ? ? ? hiddenmodalput:true,

? ? ? ? //可以通過hidden是否掩藏彈出框的屬性,來指定那個(gè)彈出框

? ? },

//點(diǎn)擊按鈕痰喘指定的hiddenmodalput彈出框

modalinput:function(){

this.setData({

? hiddenmodalput: !this.data.hiddenmodalput

})

},

//取消按鈕

cancel: function(){

? ? ? ? this.setData({

? ? ? ? ? ? hiddenmodalput: true

? ? ? ? });

? ? },

? ? //確認(rèn)

? ? confirm: function(){

? ? ? ? this.setData({

? ? ? ? hiddenmodalput: true

? ? })

? ? }


})

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 微信小程序在無(wú)論在功能、文檔及相關(guān)支持方面,都是優(yōu)于前面幾種微信賬號(hào)類型,它提供了很多原生程序才有的接口,使得我們...
    未央大佬閱讀 2,394評(píng)論 0 12
  • 1、背景圖片全屏顯示 描述:首先在小程序中顯示背景圖片的話不能使用 image ,image 只能用在顯示在最上層...
    Jiwenjie閱讀 1,690評(píng)論 0 1
  • 最近由于公司需求要做小程序開發(fā),而且做h5的前端同事現(xiàn)在都很忙,所以我們移動(dòng)開發(fā)就開始學(xué)習(xí)這個(gè)微信小程序了,...
    無(wú)灃閱讀 1,754評(píng)論 1 4
  • 經(jīng)歷了長(zhǎng)夜,守到了黎明 守行過黑暗,仍相信陽(yáng)光 帶著強(qiáng)大的內(nèi)心上路 臉上有卑微的笑容 一路看山看水,走走停停
    玖夏2閱讀 220評(píng)論 2 2
  • 一個(gè)iOS程序猿為什么要學(xué)MySQL?因?yàn)閺那八且粋€(gè)iOS程序猿,后來他轉(zhuǎn)行做PHP了。 學(xué)一門程序語(yǔ)言最快的學(xué)...
    jxdfool閱讀 2,149評(píng)論 2 13

友情鏈接更多精彩內(nèi)容