1.引入 js 和 css
- <link rel="stylesheet" href="css/main.css">
- <script src="/js/easyUploader.js"></script>
复制代码
2.div
- <div id="uploader"></div>
复制代码
3.js
- <script>
- var uploader = easyUploader({
- id: "uploader",
- name: 'download',/* input文件名称名称 */
- autoUpload: true, /* 是否开启自动上传 */
- accept: '.jpg,.png',
- action: FILEURL,
- dataFormat: 'formData',
- maxCount: 10,
- maxSize: 3,
- multiple: true,
- data: null,
- beforeUpload: function(file, data, args) {
- /* dataFormat为formData时配置发送数据的方式 */
- //data.append('token', '387126b0-7b3e-4a2a-86ad-ae5c5edd0ae6TT');
- // data.append('otherKey', 'otherValue');
- /* dataFormat为base64时配置发送数据的方式 */
- // data.base = file.base;
- // data.token = '387126b0-7b3e-4a2a-86ad-ae5c5edd0ae6TT';
- // data.otherKey = 'otherValue';
- },
- onChange: function(fileList) {
- /* input选中时触发 */
- },
- onRemove: function(removedFiles, files) {
- console.log('onRemove', removedFiles);
- },
- onSuccess: function(res,previewId) {
- console.log('onSuccess', res);
- var val = res.data;
- $("<input type='hidden' name='atts[]' value='" + val + "' />").appendTo('#' + previewId);
- },
- onError: function(err) {
- console.log('onError', err);
- },
- });
- </script>
复制代码 |