小程序:四种默认弹框

wxml代码

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


var  app = getApp()

Page({

showok:function(){

wx.showToast({

title:'成功',

icon:'success',

duration:2000

})

}

})

2,模态弹窗——wx.showModal(OBJECT)


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)


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="请输入验证码" confirm-text="提交" cancel-text="重置" bindcancel="cancel" bindconfirm="confirm">

    <input type='text'placeholder="请输入内容" auto-focus/>

</modal>

js代码

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

    })

    }


})

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 微信小程序在无论在功能、文档及相关支持方面,都是优于前面几种微信账号类型,它提供了很多原生程序才有的接口,使得我们...
    未央大佬阅读 2,338评论 0 12
  • 1、背景图片全屏显示 描述:首先在小程序中显示背景图片的话不能使用 image ,image 只能用在显示在最上层...
    Jiwenjie阅读 1,606评论 0 1
  • 最近由于公司需求要做小程序开发,而且做h5的前端同事现在都很忙,所以我们移动开发就开始学习这个微信小程序了,...
    无沣阅读 1,646评论 1 4
  • 经历了长夜,守到了黎明 守行过黑暗,仍相信阳光 带着强大的内心上路 脸上有卑微的笑容 一路看山看水,走走停停
    玖夏2阅读 210评论 2 2
  • 一个iOS程序猿为什么要学MySQL?因为从前他是一个iOS程序猿,后来他转行做PHP了。 学一门程序语言最快的学...
    jxdfool阅读 2,104评论 2 13