亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery實(shí)現(xiàn)多張圖片上傳預(yù)覽(不經(jīng)過后端處理)

 更新時(shí)間:2017年04月29日 10:44:36   作者:15868870855  
本篇文章主要介紹了jQuery實(shí)現(xiàn)多張圖片上傳預(yù)覽(不經(jīng)過后端處理)的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來看下吧

效果圖:

圖(1)

圖(2)

代碼如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery圖片上傳預(yù)覽(不經(jīng)過后端處理)</title>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<div>
 <img class="ImgPr"/>
 <input type="file" class="up" />
</div>
<div>
 <img class="ImgPr"/>
 <input type="file" class="up" />
</div>
<script>
jQuery.fn.extend({
   uploadPreview: function(opts) {
    var _self = this,
      _this = $(this);
    opts = jQuery.extend({
     Img: "ImgPr",
     Width: 100,
     Height: 100,
     ImgType: ["gif", "jpeg", "jpg", "bmp", "png"],
     Callback: function() {}
    }, opts || {});
    _self.getObjectURL = function(file) {
     var url = null;
     if (window.createObjectURL != undefined) {
      url = window.createObjectURL(file)
     } else if (window.URL != undefined) {
      url = window.URL.createObjectURL(file)
     } else if (window.webkitURL != undefined) {
      url = window.webkitURL.createObjectURL(file)
     }
     return url
    };
    _this.change(function() {
     if (this.value) {
      if (!RegExp("\.(" + opts.ImgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {
       alert("選擇文件錯(cuò)誤,圖片類型必須是" + opts.ImgType.join(",") + "中的一種");
       this.value = "";
       return false
      }
      //高版本Jquey使用 if ($.support.leadingWhitespace)
      if ($.support.leadingWhitespace) { //低版本jquery中使用$.browser.msie

       console.log(_self.getObjectURL(this.files[0]));
       try {
        _this.parent('div').find("." + opts.Img).attr('src', _self.getObjectURL(this.files[0]));
       } catch (e) {
        var src = "";
        var obj = _this.parent('div').find("." + opts.Img);
        var div = obj.parent("div")[0];
        _self.select();
        if (top != self) {
         window.parent.document.body.focus()
        } else {
         _self.blur()
        }
        src = document.selection.createRange().text;
        document.selection.empty();
        obj.hide();
        obj.parent("div").css({
         'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)',
         'width': opts.Width + 'px',
         'height': opts.Height + 'px'
        });
        div.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src
       }
      } else {
       _this.parent('div').find("." + opts.Img).attr('src', _self.getObjectURL(this.files[0]))
      }
      opts.Callback()
     }
    })
   }
  });
  $(".up").click(function(){
   $(this).uploadPreview({
    Img: "ImgPr"
   });
  })

</script>
</body>
</html>

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

  • jquery實(shí)現(xiàn)界面無刷新加載登陸注冊(cè)

    jquery實(shí)現(xiàn)界面無刷新加載登陸注冊(cè)

    這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)界面無刷新加載登陸注冊(cè),具有一定的參考價(jià)值,感興趣的朋友可以參考一下
    2016-07-07
  • 最新評(píng)論