使用showLoaderOnConfirm时,禁用Sweet Alert中的输入文本框

时间:2016-05-20 09:45:58

标签: javascript jquery html css sweetalert

我正在使用Sweet Alert插件创建一个按钮并创建一个弹出窗口以删除某些内容 我想在删除过程运行时禁用文本框,我不知道该怎么办,有人带领我吗?

jQuery("#vbb_btn_delete_post").on("click", function(e) {
        swal({
            title: "Lý do xóa bài",
            type: "input",
            showCancelButton: true,
            closeOnConfirm: false,
            animation: "slide-from-top",
            inputPlaceholder: "Write something",
            showLoaderOnConfirm: true,
            customClass: "mySwall"
        },      
        function(inputValue){
            if (inputValue === false) return false;
            if (inputValue === "") {
              swal.showInputError("Bạn cần nhập lý do"); return false;   
            } 
            $('.mySwall').find(':text').prop('disabled', true); //it not working ???          
            jQuery.ajax({
                url: "http://staging.webtretho.vn/forum/editpost.php?do=deletepost&p={vb:raw postinfo.postid}",
                type: "POST",
                data: {
                    "dodelete": "1",
                    "deletepost": "delete",
                    "reason": inputValue,
                    "securitytoken": "{vb:raw bbuserinfo.securitytoken}",
                    "p": {vb:raw postinfo.postid},
                    "url": "{vb:raw url}",
                    "do": "deletepost",
                    "posid": {vb:raw postinfo.postid},
                    "forumid": {vb:raw $GLOBALS.forumid}
                },
                dataType: "html",
                success: function () {
                    //console.log(data);
                    swal("Done!","It was succesfully deleted!","success");
                    window.location="http://staging.webtretho.vn/forum/f"+{vb:raw $GLOBALS.forumid};
                }
            });
        //swal("Nice!", "You wrote: " + inputValue, "success");
        })
});

2 个答案:

答案 0 :(得分:1)

要禁用文本框:

$("input").prop('disabled', true);
$("input").prop('disabled', false);

答案 1 :(得分:1)

如果您想在执行ajax调用之前禁用SweetAlert中的输入文本框:

$(function () {
  $('#btn').on('click', function (e) {
    //$(this).prop('disabled', true);
    swal({
      title: "Ajax request example",
      text: "Submit to run ajax request",
      type: "input",
      inputPlaceholder: "Write something",
      showCancelButton: true,
      closeOnConfirm: false,
      showLoaderOnConfirm: true,
      customClass: "mySwal"
    }, function (inputValue) {
      if (inputValue === "") {
        swal.showInputError("You need to write something!");
        return false
      }
      $('.mySwal').find(':text').prop('disabled', true);
      setTimeout(function () {
        swal("Ajax request finished!");
      }, 5000);
    });
  });
});
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>

<button id="btn">Click me To delete</button>