jQuery启用禁用按钮防止重复提交、layer.confirm确定按钮锁定防止重复触发事件

走远了吗. 提交于 2020-02-04 15:54:48
<a class="btn btn-warning" id="releaseBtn" onclick="ShipPlanManager.release()">
 <i class="fa fa-pencil"></i> 计划下发
</a>
/**
 * 计划下发
 */
ShipPlanManager.release = function () {
 if (this.check()) {
     //禁用按钮
     $("#releaseBtn").attr("disabled", true);
     $("#releaseBtn").removeAttr("onclick");
     var data = $('#' + this.id).bootstrapTable('getSelections');
     var ids = "";
     for (var i = 0; i < data.length; i++) {
         ids = ids + data[i].id + ",";
     }
     ids = ids.substring(0, ids.length - 1);
     var lock = false;//默认未锁定
     parent.layer.confirm('是否确认下发?', {
         btn: ['确定', '取消'],
         shade: false, //不显示遮罩
     }, function () {
         if (!lock) {
             lock = true;
             var ajax = new $ax(Feng.ctxPath + "/shipplanmanager/release", function (data) {
                 Feng.success("计划下发成功!");
                 ShipPlanManager.table.refresh();
                 //启用按钮
                 $("#releaseBtn").removeAttr("disabled");
                 $("#releaseBtn").attr("onclick", "ShipPlanManager.release()");
             }, function (data) {
                 Feng.error("计划下发失败!" + data.responseJSON.message + "!");
                 $("#releaseBtn").removeAttr("disabled");
                 $("#releaseBtn").attr("onclick", "ShipPlanManager.release()");
             });
             ajax.set("ids", ids);
             ajax.start();
         }
     }, function () {
         $("#releaseBtn").removeAttr("disabled");
         $("#releaseBtn").attr("onclick", "ShipPlanManager.release()");
     })
 }
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!