1.模态框

  1. <view class="modalBox">
  2. <button bindtap="modalFunc">modal模态框</button>
  3. <button bindtap="createModal">动态创建模态框</button>
  4. </view>
  5. <!-- 提示框 -->
  6. <modal title="提示" confirm-text="确认" cancel-text="取消" hidden="{{modalHidden}}" mask bindconfirm="confirmFunc" bindcancel="cancelFunc">
  7. 是否确认提交?
  8. </modal>
  1. data: {
  2. //false显示,true为隐藏
  3. modalHidden:true
  4. },
  5. // 模态框出现
  6. modalFunc:function(){
  7. // 显示提示框
  8. this.setData({
  9. modalHidden: false
  10. });
  11. },
  12. // 动态创建模态框
  13. createModal:function(){
  14. wx.showModal({
  15. title: '动态创建模态框',
  16. content: '本框测试用的哈',
  17. success: function (res) {
  18. if (res.confirm) {
  19. console.log('用户点击确定')
  20. } else if (res.cancel) {
  21. console.log('用户点击取消')
  22. }
  23. }
  24. })
  25. },
  26. // 确认函数
  27. confirmFunc:function(){
  28. console.log("点击了确认!");
  29. // 关闭提示框
  30. this.setData({
  31. modalHidden: true
  32. });
  33. },
  34. // 取消函数
  35. cancelFunc:function(){
  36. console.log("点击了取消!");
  37. // 关闭提示框
  38. this.setData({
  39. modalHidden: true
  40. });
  41. },

效果图:
弹窗 - 图1
弹窗 - 图2
弹窗 - 图3

2.提示框

<view class="modalBox">
  <button bindtap="toastFunc">toast提示框</button>
   <button bindtap="createToast">动态创建toast提示框</button>
</view>     


<!-- 提示框 -->
  <toast hidden="{{toastHidden}}">提交成功</toast>
data: {
     //false显示,true为隐藏
    toastHidden:true
  },

  // 提示框出现
  toastFunc:function(){
    // 显示提示框
    this.setData({
      toastHidden: false
    });

    // 两秒后提示框消失
    var that = this;
    setTimeout(function(){
      that.setData({
        toastHidden: true
      });
    },2000);

  },

  // 动态创建提示框
  createToast:function(){
     wx.showToast({
       title: '设置成功',
     })
  },

效果图:
弹窗 - 图4