当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 使用微信小程序开发弹出框应用实例详解

使用微信小程序开发弹出框应用实例详解

2019年06月02日  | 移动技术网IT编程  | 我要评论

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: '成功',
		 	icon: 'success',
		 	duration: 2000
		})
	}
})

2.模态弹窗——wx.showmodal(object)

//show.js
//获取应用实例 
var app = getapp() 
page({
	showok:function() {
		wx.showtoast({
		 	title: '成功',
		 	icon: 'success',
		 	duration: 2000
		})
	}
})

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

//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弹出

指定哪个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='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
	 })
 }
})

总结

以上所述是小编给大家介绍的使用微信小程序开发弹出框应用实例详解,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网