(轉)微信小程序開發—彈出框

原文地址html

<span style="font-family:Comic Sans MS;font-size:18px;color:#333333;"><view class="container" class="zn-uploadimg">  
    <button type="primary"bindtap="showok">消息提示框</button>   
    <button type="primary"bindtap="modalcnt">模態彈窗</button>   
    <button type="primary"bindtap="actioncnt">操做菜單</button>   
</view></span>

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

<span style="font-family:Comic Sans MS;font-size:18px;color:#333333;">//show.js //獲取應用實例 var app = getApp() Page({ showok:function() { wx.showToast({ title: '成功', icon: 'success', duration: 2000 }) } }) </span>

2.模態彈窗——wx.showModal(OBJECT)

//show.js  //獲取應用實例 
var app = getApp() Page({ modalcnt:function(){ wx.showModal({ title: '提示', content: '這是一個模態彈窗', success: function(res) { if (res.confirm) { console.log('用戶點擊肯定') } else if (res.cancel) { console.log('用戶點擊取消') } } }) } }) 

3.操做菜單——wx.showActionSheet(OBJECT)api

//show.js  //獲取應用實例 
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彈出app

指定哪一個modal,能夠經過hidden屬性來進行選擇。this

<!--show.wxml-->  
<view class="container" class="zn-uploadimg">  
    <button type="primary"bindtap="modalinput">modal有輸入框</button>   
</view>  
<modal hidden="{{hiddenmodalput}}" title="請輸入驗證碼" confirm-text="提交" cancel-text="重置" bindcancel="cancel" bindconfirm="confirm">  
    <input type='text'placeholder="請輸入內容" auto-focus/>  
</modal>
//show.js  //獲取應用實例 
var app = getApp() Page({ data:{ hiddenmodalput:true, //能夠經過hidden是否掩藏彈出框的屬性,來指定那個彈出框 
 }, //點擊按鈕痰喘指定的hiddenmodalput彈出框 
    modalinput:function(){ this.setData({ hiddenmodalput: !this.data.hiddenmodalput }) }, //取消按鈕 
    cancel: function(){ this.setData({ hiddenmodalput: true }); }, //確認 
    confirm: function(){ this.setData({ hiddenmodalput: true }) } }) 

相關文章
相關標籤/搜索