您当前的位置: 首页 > 解决方案

小程序弹出框详解

  • 作者: admin
  • 发布于 2018-12-21 09:19:36
  • 来源:  
  • 栏目:解决方案

导语: 小程序弹出框详解" style="margin: 20px 0px; font-family: "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", "Microsoft Yah

 

 
  1. qjlx: function() {
  2. var itemList = ['病假', '事假'];
  3. wx.showActionSheet({
  4. itemList: itemList,
  5. success: function(res) {
  6. console.log(res);
  7. console.log(itemList[res.tapIndex]);
  8. },
  9. fail: function(res) {
  10. console.log(res.errMsg);
  11. }
  12. })
  13. },

操作菜单——wx.showActionSheet(OBJECT)

02.jpg

效果

03.jpg

效果

 
  1. //获取应用实例
  2. var app = getApp()
  3. Page({
  4. actioncnt:function(){
  5. wx.showActionSheet({
  6. itemList: ['A', 'B', 'C'],
  7. success: function(res) {
  8. console.log(res.tapIndex)
  9. },
  10. fail: function(res) {
  11. console.log(res.errMsg)
  12. }
  13. })
  14. }
  15. })

04.jpg

弹出框

 
  1. <view class='item'>
  2. 登录密码
  3. <view class='bk'>
  4. <input class="textarea" placeholder="{{password}}" value='{{password}}' bindinput="password" maxlength='100' auto-height disabled/>
  5. </view>
  6.  
  7. <button class='btn' bindtap='dlmm'>修改</button>
  8. <modal hidden="{{hiddenmodalput}}" title="修改密码" confirm-text="提交" cancel-text="取消" bindcancel="cancelM" bindconfirm="confirmM">
  9. <input bindinput='ipsd' type='text' placeholder="请输入原密码..." auto-focus/>
  10. <input bindinput='newipsd' type='password' placeholder="请输入新密码..." />
  11. </modal>
  12.  
  13. </view>
 
  1. // js
  2. // 获取登录密码:
  3. password: function(e) {
  4. this.setData({
  5. password: e.detail.value,
  6. })
  7. console.log("获取登录密码:" + this.data.password);
  8. },
  9. // 修改登录密码
  10. dlmm: function(e) {
  11. this.setData({
  12. hiddenmodalput: !this.data.hiddenmodalput
  13. })
  14. },
  15. cancelM: function(e) {
  16. this.setData({
  17. hiddenmodalput: true,
  18. })
  19. },
  20.  
  21. confirmM: function(e) {
  22. var that = this;
  23. console.log("原密码" + that.data.psd + "新密码" + that.data.newpsd);
  24. that.setData({
  25. hiddenmodalput: true,
  26. })
  27. wx.request({
  28. url: '',
  29. method: 'POST',
  30. header: {
  31. 'Authorization': 'Bearer' + wx.getStorageSync('token'),
  32. },
  33. success(res) {
  34. if (res.data.code == 0) {
  35. wx.showToast({
  36. title: '保存失败',
  37. icon: 'success',
  38. duration: 500
  39. })
  40. } else {
  41. that.getShowToast();
  42. }
  43. }
  44. })
  45. },
  46.  
  47. ipsd: function(e) {
  48. this.setData({
  49. psd: e.detail.value
  50. })
  51. },
  52. newipsd: function(e) {
  53. this.setData({
  54. newpsd: e.detail.value
  55. })
  56. },

指定modal弹出

05.jpg

效果

 
  1. <!--show.wxml-->
  2. <view class="container" class="zn-uploadimg">
  3. <button type="primary"bindtap="modalinput">modal有输入框</button>
  4. </view>
  5. <modal hidden="{{hiddenmodalput}}" title="请输入验证码" confirm-text="提交" cancel-text="重置" bindcancel="cancel" bindconfirm="confirm">
  6. <input type='text'placeholder="请输入内容" auto-focus/>
  7. </modal>
 
  1. //获取应用实例
  2. var app = getApp()
  3. Page({
  4. data:{
  5. hiddenmodalput:true,
  6. //可以通过hidden是否掩藏弹出框的属性,来指定那个弹出框
  7. },
  8. //点击按钮痰喘指定的hiddenmodalput弹出框
  9. modalinput:function(){
  10. this.setData({
  11. hiddenmodalput: !this.data.hiddenmodalput
  12. })
  13. },
  14. //取消按钮
  15. cancel: function(){
  16. this.setData({
  17. hiddenmodalput: true
  18. });
  19. },
  20. //确认
  21. confirm: function(){
  22. this.setData({
  23. hiddenmodalput: true
  24. })
  25. }
  26.  
  27. })

06.jpg

效果

 
  1. //获取应用实例
  2. var app = getApp()
  3. Page({
  4. actioncnt:function(){
  5. wx.showActionSheet({
  6. itemList: ['A', 'B', 'C'],
  7. success: function(res) {
  8. console.log(res.tapIndex)
  9. },
  10. fail: function(res) {
  11. console.log(res.errMsg)
  12. }
  13. })
  14. }
  15. })
 
  1. <!--.wxml-->
  2. <view class="container" class="zn-uploadimg">
  3. <button type="primary"bindtap="modalinput">modal有输入框</button>
  4. </view>
  5. <modal hidden="{{hiddenmodalput}}" title="请输入验证码" confirm-text="提交" cancel-text="重置" bindcancel="cancel" bindconfirm="confirm">
  6. <input type='text'placeholder="请输入内容" auto-focus/>
  7. </modal>
  8.  
  9. //.js
  10. //获取应用实例
  11. var app = getApp()
  12. Page({
  13. data:{
  14. hiddenmodalput:true,
  15. //可以通过hidden是否掩藏弹出框的属性,来指定那个弹出框
  16. },
  17.  
  18. //点击按钮痰喘指定的hiddenmodalput弹出框
  19. modalinput:function(){
  20. this.setData({
  21. hiddenmodalput: !this.data.hiddenmodalput
  22. })
  23. },
  24. //取消按钮
  25. cancel: function(){
  26. this.setData({
  27. hiddenmodalput: true
  28. });
  29. },
  30. //确认
  31. confirm: function(){
  32. this.setData({
  33. hiddenmodalput: true
  34. })
  35. }
  36. })
 
  1. 达叔小生:往后余生,唯独有你
  2. You and me, we are family !
  3. 90后帅气小伙,良好的开发习惯;独立思考的能力;主动并且善于沟通
  4. 简书博客: 达叔小生
  5. https://www.jianshu.com/u/c785ece603d1
 

结语

下面我将继续对 其他知识 深入讲解 ,有兴趣可以继续关注 
小礼物走一走 or 点赞

 

 



温馨提示:这篇文章没有解决您的问题?欢迎添加微信:18948083295,有微信小程序专业人员,保证有问必答。转载本站文章请注明转自http://www.okeydown.com/(微信小程序网)。

  • 微信扫描二维码关注官方微信
  • ▲长按图片识别二维码
关注我们

微信小程序官方微信

栏目最新
栏目推荐
返回顶部