1.下载ajaxfileupload.js

2.js源码:

<script src="/medias/ajaxfileupload.js" type="text/javascript"></script>

<style type="text/css">
#loading {
  background-color:gray;
  position:fixed;
  left:0;
  top:0;
  width:100%;
  height:100%;
  z-index:100000;
  opacity:0.2;
  filter:alpha(opacity=20);
  -moz-opacity:0.2;
  -khtml-opacity:0.2;
  vertical-align:middle;
}

#loading div {
  position:absolute;
  left:40%;
  top:50%;
}

#loading div span {
  color:#000000;
  font-weight:700;
}
</style>
<script type="text/javascript">
function uploadSubmit(){
  var file = $('#fileToUpload').val();
  //检查是否已选择上传文件
  if (file != '') {
    var filename = file.replace(/.*(\/|\\)/, '');
    var fileext = (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename.toLowerCase()) : '';
    //检查文件格式
    if (fileext == 'xlsx' || fileext == 'xls') {
      //展示等待信息
      $('#loading').ajaxStart(function(){
        $(this).show();
        }).ajaxComplete(function(){
        $(this).hide();
      });

      //上传excel文件
      $.ajaxFileUpload({
        url: 自己的url,
        secureuri: false,
        dataType: "text",
        fileElementId: 'fileToUpload',
        success: function(data){       //data是后台返回过来的在上传并保持excel内容过程中的用户提示信息
        $("#result").html(data);
        $("#result").dialog("open");
        },
      });
    }
    else {
      alert('文件格式必须是*.xls或*.xlsx');
    }
  }
  else {
    alert('请选择excel文件!')
  }
};


//初始化用户提示窗口 
$(function(){
  $("#result").dialog({
    autoOpen: false,
    height: 140,
    modal: true,
    buttons: {
      Ok: function(){
        $(this).dialog("close");
      }
    }
  });
});

</script>

3.html源码
<form name="form" action="" method="POST" enctype="multipart/form-data">
  <input >正在操作,请稍候... ...</span></div>
</div>

相关文章:

  • 2021-09-15
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-04
  • 2021-12-27
猜你喜欢
  • 2022-01-01
  • 2021-09-01
  • 2021-07-20
  • 2021-12-14
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案