JQuery實現 圖片上傳


用到的文件,我都已經打包好了,自行下載:

https://files.cnblogs.com/files/lguow/lib.rar

核心代碼如下:

<input type="hidden" name="avatar" id="avatar">
<img src="" alt="" id="avatarShow" width="200px" height="200px">


<span>上傳頭像</span>
<input type="file" name="file" id="file" onchange="uploadImg();"  >

<script>
function uploadImg() {
    debugger;
    if($("#file").val() != "") {
        $.ajaxFileUpload({
            type: "POST",
            url:"/selfsuperXXXXX/uploadFile",//后台接口
            dataType: "json",
            fileElementId:"file",  // 文件的id
            success: function(d){
                if(d.code == 0) {
                    js.showMessage("上傳成功");
                    //圖片顯示
                    $("#avatar").attr("value",d.data.url);
                    $("#avatarShow").attr("src",d.data.url);
                }
            },
            error: function () {
                js.showMessage("上傳失敗");
            },
        });
    } else {
        js.showMessage("請先選擇文件");
    }
}
</script.

湊字數用。。。。。。。。。。。。。。湊字數用。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。湊字數用。。。。。。。。。。。。。。。。。。。。。。。。湊字數用。。。。。。。。。。。。。。。。。。。。。。。。。。湊字數用。。。。。。。。。湊字數用。。。。。。。。。。。。。湊字數用。。。。。。。。。。。。。。。。。。。。。。湊字數用。。。。。。。。。。。。湊字數用湊字數用湊字數用湊字數用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM