簡單實現一個檔案上傳的進度條

來源:互聯網
上載者:User

新手初學web 檔案上傳做完了 進度做了 沒有進度條只有文字 不太好看  需要做個進度條  沒有美工 網上很多的 進度條 需要圖片 還有各種架構 看著好麻煩 只好自己弄一個 還挺簡單的 沒想象的那麼複雜  分享一下 

jsp頁面

<tr>
<td width="100">圖片</td>
<td>
<div style="width: 450px;">
<div class="file-box">
<input type='text' name='textfieldimg' id='textfieldimg' class='txt' /> 
<input type='button' class='btn' value='瀏覽...' /> 
<input type="file" name="file" class="file" id="fileupload2" size="28" onchange="document.getElementById('textfieldimg').value=this.value"   data-url="http://192.168.6.53:8080/upload" />
</div>
<div id="div_progress2" style="visibility: hidden;" class="progress_div1"  >
<div class="progress_div3" >
<div id="pro2" style="float: left;width: 0px;background-color: blue; height: 15px;"></div>
</div>
<div class="progress_div2"><span style="margin-left: 10px;" id="progress2"></span></div>
</div>
</div>
</td>
<td></td>
</tr>

js

<script type="text/javascript"
src="${pageContext.request.contextPath}/js/jquery.ui.widget.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/jquery.iframe-transport.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/jquery.fileupload.js"></script>

<script type="text/javascript"
src="${pageContext.request.contextPath}/script/jquery-1.8.3.min.js"></script>

$('#fileupload2').fileupload({
progress: function (e, data) {
var pro = parseInt(data.loaded / data.total * 100, 10);
var div2 = document.getElementById("div_progress2");
   div2.style.visibility = "visible";
   var p2 = document.getElementById("pro2");
   p2.style.width=pro;
   $('#progress2').text(pro + '%');
   if(pro==100){
    $('#progress2').text('上傳成功');
var path2 = document.getElementById('textfieldimg').value;
            var name2 = getFileName(path2);
            document.getElementById('imageFilename').innerText = name2;
     
   }
}
});
});

css  


.txt {
height: 22px;
border: 1px solid #91c0e3;
width: 180px;
}


.btn {
background-color: #FFF;
border: 1px solid #CDCDCD;
height: 24px;
width: 70px;
}


.file-box {
float:left;
position: relative;
width: 260px
}


.file {
position: absolute;
top: 0;
right: 10px;
height: 24px;
filter: alpha(opacity : 0);
opacity: 0;
width: 260px
}


.progress_div1{

width:190px;
height:20px; 
vertical-align:middle;
margin-left: auto;
}


.progress_div2{

margin-left:auto;
width:90px;
height:20px;
vertical-align: middle;
 padding-top: 3px;
}


.progress_div3{

float:left;
width: 100px;
height: 15px; 
background-color: white; 
border:solid 1px blue;
vertical-align: middle;
margin-top: 3px; 
 
}






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.