jquery外掛程式fileupload圖片上傳(前端如何處理)

來源:互聯網
上載者:User

標籤:process   hid   block   pac   nbsp   one   mil   abs   部分   

1.頁面首先引入jquery,版本不要低於1.6
   <script src="../js/jquery.min.js"></script>
2.其次頁面引入對應的這個五個js,按順序放置
<script src="../js/jquery.ui.widget.js"></script>
<script src="../js/jquery.iframe-transport.js"></script>
   <script src="../js/jquery.fileupload.js"></script>
   <script src="../js/jquery.fileupload-process.js"></script>
   <script src="../js/jquery.fileupload-ui.js"></script>
3.html結構如下:
  <div class="control-group"><label>上傳頭像:</label>
<div class="controls upload-bg"><!---->
<input class="upload" id="file" type="file" name="file">
<img src="" style="display:none;width:100%;height:100%" id="target" alt="[Jcrop Example]"/>
<input type="hidden" value="" id="url">
</div>
<p class="reupload">重新上傳
<input class="imgEditor" id="uploadNext" type="file" name="file" value=""/>
  </p>
</div>
這個樣式是這樣的:
4.css樣式如下:如有些結構和樣式不一致的,希望自己調整一下
  /*上傳圖片*/
.control-group .upload {
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
}

.control-group .upload-bg {
width: 240px;
height: 240px;
position: relative;
border: 1px solid #ccc;
background: url("../images/upload.png") center no-repeat;
margin-left: 200px;
margin-top: -25px;
}
.control-group .upload-bg:hover {
border: 1px dashed #0000FF;
transition: border 1s;
}
.control-group .upload-bg p, .imgEditor {
position: absolute;
bottom: 0;
display: none;
text-align: center;
width: 100%;
margin: 0;
background: #210606;
opacity: 0.6;
color: #ccc;
cursor: pointer;

}
.control-group .upload-bg:hover {
border: 1px dashed #0000FF;
transition: border 1s;
}
.fm .reupload{margin-bottom:0 !important;}
.control-group .upload-bg p, .imgEditor {
position: absolute;
bottom: 0;
display: none;
text-align: center;
width: 100%;
margin: 0;
background: #210606;
opacity: 0.6;
color: #ccc;
cursor: pointer;

}
.imgEditor {
opacity: 0;
z-index: 2;
left: 0;
height: 100% !important;
display: block;

}

.reupload{
margin-top:2px;
position: relative;
height: 24px !important;
width: 243px !important;
margin-left: 200px;
line-height: 24px;
background: #9999CC;
display: none;
}
5.上傳的js部分:
function imgUpLoad(eleId) {
$(‘#‘ + eleId).fileupload({
autoUpload: true,//自動上傳
url: "http://xxxxx.url",//?上傳圖片對應的地址
dataType: ‘json‘,
done: function (e, data) {
var oimage = data, _this = $(‘#‘ + eleId);
if (eleId == ‘file‘) {
_this.hide();
_this.siblings(‘img‘).attr(‘src‘, oimage.result.url).show();
$(‘.reupload‘).show();//第一次上傳完成,顯示重新上傳

} else {//重新上傳
_this.closest(‘.control-group‘).find(‘#target‘).attr(‘src‘, oimage.result.url);
}
}
})
}
6.最後上傳完成之後是這樣的(其實還有裁剪的功能,下一篇介紹)

 

jquery外掛程式fileupload圖片上傳(前端如何處理)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.