easyui 圖片上傳功能詳解

來源:互聯網
上載者:User

標籤:

頁面展示:

   1、點擊圖片上傳 跳轉頁面 攜帶2個參數  ID  NAME=所屬模組       jsp   js  可以上傳檔案和圖片代碼:  $(function() {
var falg=0;
    $list = $(‘#thelist‘);
    var uploader = WebUploader.create({
        // 選完檔案後,是否自動上傳。
        auto : false,
        // swf檔案路徑
        swf : ‘plugins/expand/webuploader/Uploadify.swf‘,
        // 檔案接收服務端。
        server : ‘commAction_saveFile‘,//url
        // 選擇檔案的按鈕。可選。
        // 內部根據當前運行是建立,可能是input元素,也可能是flash.
        pick : ‘#picker‘,
        // 只允許選擇圖片檔案。
        formData : {
            belongId : $(‘#belongId‘).val(),
            belongMode : $(‘#belongMode‘).val()
        }
    });
    uploader.on(‘fileQueued‘, function(file) {
        $list.append(‘<div id="‘ + file.id + ‘" class="item">‘
                + ‘<h4 class="info">‘ + file.name + ‘</h4>‘
                + ‘<p class="state">等待上傳...</p>‘ + ‘</div>‘);
                var belongMode=$(‘#belongMode‘).val();
                //只有是發票登記的時候 只能上傳圖片
            if(belongMode==‘發票登記‘){
                var fileName=file.name;//擷取上傳圖片的名稱
                //判斷是不是圖片
                var fileType = fileName.substring(fileName.lastIndexOf(".") +1,fileName.length);
                if (fileType == ‘png‘
                                                || fileType == ‘jpg‘
                                                || fileType == ‘jpeg‘
                                                || fileType == ‘gif‘
                                                || fileType == ‘bmp‘
                                                || fileType == ‘raw‘){
                                                falg=0;
                }else{
                    $.messager.alert(‘錯誤提示‘, "請選擇一張圖片上傳", ‘error‘)
                    falg=1;
                    return;
                    }
                }
                
    })
    
    // 檔案上傳成功,給item添加成功class, 用樣式標記上傳成功。
    uploader.on(‘uploadSuccess‘, function(file, response) {
        $(‘#‘ + file.id).addClass(‘upload-state-done‘);
        switch (response.flag) {
        case 0:
            closeWin();
            break;
        case 1:
            $.messager.alert(‘錯誤提示‘, response.info, ‘error‘)
            break
        }
    });
    $(‘#save‘).on(‘click‘, function() {
    //判斷是不是圖片
    if(falg==1){
        return;
    }
        uploader.upload();
    });

})根據url 到Action 代碼:最後就是將資料存在資料庫。

easyui 圖片上傳功能詳解

聯繫我們

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