Simple JS FileUpload Control

Source: Internet
Author: User

File_upload_demo.html

<! Doctype html>

simple_file_ Upload.js

(function ($) {    var defaultsettings = {         accepttypes:["JPG", "png"], //  accepted upload file type          changecallback:function (file) {        } //  custom input[ Type=file] change Event     };    var renderHtml =  " <input type= ' file '  style= ' Display:none; ' /> ";    //  add hidden     function renderinputfile (target, Settings) {        //  Generate dialog unique identity          var id =  "Ys_simple_file_upload_" +new date (). GetTime () + "" +parseint ( Math.random ());         $ (target) attr ("Ys_simple_file_upload", id);         $ (renderhtml). attr ("id", id). appendTo ("HTML");nbsp;//  added to the document to         return $ ("#" +id);     }    function bindeventhandlers (container,settings) {         var changeCallback = settings.changeCallback;         $ (Container). Change (function (e) {             e.preventdefault ();             E.stoppropagation ();             var file  = e.target.files[0];            if (! Validatefiletype (file,settings)) {                 alert ("Incorrect file type!");                 return;            }             changecallback (file);         });    }    //  verify file Type     function  Validatefiletype (file,settings) {        var accepttypes =  settings.accepttypes;        var name = file.name ;         var filesuffix = name.substr (Name.lastIndexOf ( ".") +1);         for (var i=0;i<accepttypes.length;i++) {             var acceptType = acceptTypes[i];             if (Accepttype==filesuffix) {                 return true;             }        }         return false;    }    var  options = {        simpleuploadfile:function (Settings)  {            var mergedsettings =  {};            $.extend (MergedSettings, Defaultsettings,settings);            var  Container = renderinputfile (this,mergedsettings);             bindeventhandlers (container,mergedsettings);             $ (this). Click (function (E) {                 e.preventdefault ();                 e.stoppropagation ();                 $ (Container). Click ();             });        }    };     $.fn.extend (options);}) (JQuery);

Simple JS FileUpload control

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.