首頁  >  文章  >  微信小程式  >  微信小程式開發彈出框實作方法

微信小程式開發彈出框實作方法

小云云
小云云原創
2018-03-17 12:05:2630238瀏覽

本文主要和大家分享微信小程式開發彈出框實作方法,本文所分享的程式碼很清晰,希望能幫助大家。


<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>

1.訊息提示-wx.showToast(OBJECT)

#
//show.js
//获取应用实例  
var app = getApp()  
Page({
	showok:function() {
		wx.showToast({
		  	title: &#39;成功&#39;,
		  	icon: &#39;success&#39;,
		  	duration: 2000
		})
	}
})

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



#

//show.js
//获取应用实例  
var app = getApp()  
Page({
	modalcnt:function(){
		wx.showModal({
			title: &#39;提示&#39;,
			content: &#39;这是一个模态弹窗&#39;,
			success: function(res) {
				if (res.confirm) {
				console.log(&#39;用户点击确定&#39;)
				} else if (res.cancel) {
				console.log(&#39;用户点击取消&#39;)
				}
			}
		})
	}
})



3.操作選單-wx.showActionSheet(OBJECT)


<br/>

//show.js
//获取应用实例  
var app = getApp()  
Page({
	actioncnt:function(){
		wx.showActionSheet({
			itemList: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;],
			success: function(res) {
				console.log(res.tapIndex)
			},
			fail: function(res) {
				console.log(res.errMsg)
			}
		})
	}
})



4.指定modal彈出



#   指定哪個modal,可以透過hidden屬性來進行選擇。

#

<!--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=&#39;text&#39;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
	    })
    }
    
})

###相關推薦:###### ##如何用JQuery寫出登入彈出框############推薦10款實作彈出框特效(收藏)############分享HTML5實作彈出框的效果範例######

以上是微信小程式開發彈出框實作方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn