欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

微信小程序 确认框的实现(附代码)

时间:2021-03-18 09:45:08|栏目:JavaScript代码|点击:

效果图如下:

核心代码如下:

delType:function(e){

 var typeId = e.currentTarget.dataset['id'];

 console.log("delete:"+typeId)


 wx.showModal({
  title: '提示',
  content: '确认要删除该支出类型?',
  success: function (res) {
   if (res.confirm) {
    console.log('用户点击确定')

    wx.request({

     url: getApp().globalData.urlPath + "spendingType/delete",
     method: "POST",
     data: {
      typeId: typeId
     },
     header: {
      "Content-Type": "application/x-www-form-urlencoded"
     },
     success: function (res) {
      console.log(res.data.code);
      if (res.statusCode == 200) {

       //访问正常
       if (res.data.code == "000000") {
        wx.showToast({
         title: "删除成功,返回支出类型列表",
         icon: 'success',
         duration: 3000,
         success: function () {

          wx.navigateTo({
           url: '../type/type'
          })
         }
        })

       }
      } else {

       wx.showLoading({
        title: '系统异常',
        fail
       })

       setTimeout(function () {
        wx.hideLoading()
       }, 2000)
      }

     }
    })


   } else if (res.cancel) {
    console.log('用户点击取消')
   }
  }
 })

}

wxml代码如下:

<text bindtap='delType' data-id="{{item.typeId}}">删除</text>

data-id相当于绑定对应的值,比方说你是根据id来删除对应的数据。

bindtap,即绑定事件。

上一篇:这段js代码得节约你多少时间

栏    目:JavaScript代码

下一篇:用iframe设置代理解决ajax跨域请求问题

本文标题:微信小程序 确认框的实现(附代码)

本文地址:http://www.codeinn.net/misctech/83044.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有