欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery檢測(cè)上傳文件大小示例

 更新時(shí)間:2020年04月26日 10:36:10   作者:DavidHHuan  
這篇文章主要介紹了jquery檢測(cè)上傳文件大小,結(jié)合完整示例形式分析了jquery針對(duì)上傳文件大小檢測(cè)與計(jì)算相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了jquery檢測(cè)上傳文件大小。分享給大家供大家參考,具體如下:

google了很久,基本上都是用 activeX 來實(shí)現(xiàn)~至于為什么不行,這個(gè)不多說,說一下以下方法:

已經(jīng)測(cè)試通過的瀏覽器:IE6+,firefox,chrome,其中 firefox 和 chrome 要能支持 HTML5。

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=big5">
  <title>上傳</title>
</head>
<body>
  <form action="XXXXXX" method="POST" name="FileForm" enctype="multipart/form-data">
  <div align="center">
    圖片:
    <input type="file" name="file1" size="20" id="file1" />
    <input type="button" onclick="checkFile()" /></div>
  </form>
</body>
</html> 

<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>

<script language="JavaScript" type="text/javascript">
  var fileSize = 0; //文件大小
  var SizeLimit = 1024; //上傳上限,單位:byte

  function checkFile() {
    var f = document.getElementById("file1");
    //FOR IE
    if ($.browser.msie) {
      var img = new Image();
      img.onload = checkSize;
      img.src = f.value;
    }
    //FOR Firefox,Chrome
    else {
      fileSize = f.files.item(0).size;
      checkSize();
    }
  }

  //檢查文件大小
  function checkSize() {
    //FOR IE FIX
    if ($.browser.msie) {
      fileSize = this.fileSize;
    }

    if (fileSize > SizeLimit) {
      alert('文件超過大小');
    } else {
      document.FileForm.submit();
    }
  }
</script>

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery頁面元素操作技巧匯總》、《jQuery常見事件用法與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》及《jquery選擇器用法總結(jié)

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論