jquery plugin Imgpreviewqs implementation upload picture preview _jquery

Source: Internet
Author: User

Upload picture preview, support IE6, IE7, IE8, IE9, IE10, IE11. Firefox, Chrome is not specifically tested, but the high version is supported.

Imgpreviewqs.js

/*! Relies on JQuery 1.5.2 (c) 2016 license:http://www.opensource.org/licenses/mit-license.php/(function ($) {$.fn.imgprevie WQS = function (options) {function Isie (ver) {var b = document.createelement (' b ') b.innerhtml = ' <!--[if IE ' + ver + ']><i></i><!
  [endif]--> ' return b.getelementsbytagname (' i '). length = = 1;
  Options = $.extend ({}, $.fn.imgpreviewqs.defaults,options);
  var $this =$ (this); $this. Change (function () {var regex=/(. *) \. (. *) \.
    Jpg|jpeg|gif|bmp|png) $/;
    var val = $this. val ();
      if (!regex.test (val)) {Alert ("Please select Picture");
    return false;
    } if (Browserqs.isie (8)) {HanderIE789 ($this); else if (window.
    FileReader) {handerfilereader ($this);
    else if (Browserqs.isie (9)) {HanderIE789 ($this);
    else if (Browserqs.isie (6)) {Handerother ($this);
    else if (Browserqs.isie (7)) {HanderIE789 ($this); } else{$ ("#" +options.destid). HTML (Browser does not support previewing pictures));
   
  }
  }); function Handerfilereader ($this) {var opreviewimg = null, Ofreader = new window. FileReader (), Rfilter =/^ (?: Image\/bmp|image\/cis\-cod|image\/gif|image\/ief|image\/jpeg|image\/jpeg|image\/jpeg |image\/pipeg|image\/png|image\/svg\+xml|image\/tiff|image\/x\-cmu\-raster|image\/x\-cmx|image\/x\-icon|image\ /x\-portable\-anymap|image\/x\-portable\-bitmap|image\/x\-portable\-graymap|image\/x\-portable\-pixmap|image\/
    X\-rgb|image\/x\-xbitmap|image\/x\-xpixmap|image\/x\-xwindowdump) $/i; Ofreader.onload = function (ofrevent) {$ ("#" +options.destid). HTML (" ");
     
    };
    var afiles = $this. Get (0). files;
    if (Afiles.length = = 0) {return;}
    if (!rfilter.test (Afiles[0].type)) {alert ("Please select Picture");
  Ofreader.readasdataurl (Afiles[0]); The function HanderIE789 ($this) {$ ("#" +options.destid). CSS ("filter", "Progid:DXImageTransform.Microsoft.AlphaImageL OadER (sizingmethod=scale,src= ' "+geturl ($this) +" ') "; The function Handerother ($this) {$ ("#" +options.destid). HTML (" ");
    function GetUrl ($this) {$this. Select ();
    $this. blur ();
    var imgsrc =document.selection.createrange (). text;
    Document.selection.empty ();
  return imgsrc; 
}
}; $.fn.imgpreviewqs.defaults = {destid: ""})
 (JQuery);

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.