欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS實(shí)現(xiàn)可視化文件上傳

 更新時(shí)間:2018年09月08日 14:33:33   作者:damys  
這篇文章主要為大家詳細(xì) 介紹了JS實(shí)現(xiàn)可視化文件上傳,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了JS可視化文件上傳的具體代碼,供大家參考,具體內(nèi)容如下

測試-Style

<style type="text/css">
    .imgbox,.imgbox1
    {
      position: relative;
      width: 200px;
      height: 180px;
      border: 1px solid #ddd;
      overflow: hidden;
    }
 
    .imgnum{
      left: 0px;
      top: 0px;
      margin: 0px;
      padding: 0px;
    }
    .imgnum input,.imgnum1 input {
      position: absolute;
      width: 200px;
      height: 180px;
      opacity: 0;
    }
    .imgnum img,.imgnum1 img {
      width: 100%;
      height: 100%;
    }
    .close,
    .close1 {
      color: red;
      position: absolute;
      right: 10px;
      top: 0;
      display: none;
    }
</style>

測試--HTML

<div id="img">
 
 <div class="imgbox">
 <div class="imgnum">
  <input type="file" class="filepath" />
  <span class="close">X</span>
  <img src="btn.png" class="img1" />
  <img src="" class="img2" />
 </div>
 </div>
 
</div>

JS: 需要引入jquery

<script type="text/javascript">
  $(function() {
    $(".filepath").on("change",function() {
      var srcs = getObjectURL(this.files[0]);  //獲取路徑
      $(this).nextAll(".img1").hide();     //this指的是input
      $(this).nextAll(".img2").show();     //fireBUg查看第二次換圖片不起做用
      $(this).nextAll('.close').show();     //this指的是input
      $(this).nextAll(".img2").attr("src",srcs);  //this指的是input
      $(this).val('');               //必須制空
      $(".close").on("click",function() {
        $(this).hide();             //this指的是span
        $(this).nextAll(".img2").hide();
        $(this).nextAll(".img1").show();
      })
    })
  })
 
 
 
//關(guān)鍵代碼:getObjectURL return url
  function getObjectURL(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
  };
 

//modify img
  $(function() {
    $("#img").on("change",".filepath1",function() {
      //alert($('.imgbox1').length);
      var srcs = getObjectURL(this.files[0]);  //獲取路徑
      alert(srcs);
      //this指的是input
      /* $(this).nextAll(".img22").attr("src",srcs);  //this指的是input
       $(this).nextAll(".img22").show(); //fireBUg查看第二次換圖片不起做用*/
      var htmlImg='<div class="imgbox1">'+
          '<div class="imgnum1">'+
          '<input type="file" class="filepath1" />'+
          '<span class="close1">X</span>'+
          '<img src="btn.png" class="img11" />'+
          '<img src="'+srcs+'" class="img22" />'+
          '</div>'+
          '</div>';
 
      $(this).parent().parent().before(htmlImg);
      $(this).val('');            //必須制空
      $(this).parent().parent().prev().find(".img11").hide();  //this指的是input
      $(this).parent().parent().prev().find('.close1').show();
 
      $(".close1").on("click",function() {
        $(this).hide();          //this指的是span
        $(this).nextAll(".img22").hide();
        $(this).nextAll(".img11").show();
        if($('.imgbox1').length>1){
          $(this).parent().parent().remove();
        }
 
      })
    })
  })
 
</script>

注:低版本IE不支持可視化

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

  • 開發(fā)用到的js封裝方法(20種)

    開發(fā)用到的js封裝方法(20種)

    在本問中我們給大家總結(jié)了20種開發(fā)中常用到的JS封裝方法,有需要的讀者們可以學(xué)習(xí)下。
    2018-10-10
  • JS實(shí)現(xiàn)的JSON數(shù)組去重算法示例

    JS實(shí)現(xiàn)的JSON數(shù)組去重算法示例

    這篇文章主要介紹了JS實(shí)現(xiàn)的JSON數(shù)組去重算法,結(jié)合實(shí)例形式分析了javascript針對(duì)json數(shù)組的遍歷、判斷實(shí)現(xiàn)去重復(fù)功能相關(guān)操作技巧,需要的朋友可以參考下
    2018-04-04
  • 簡單實(shí)現(xiàn)js頁面切換功能

    簡單實(shí)現(xiàn)js頁面切換功能

    這篇文章主要為大家詳細(xì)介紹了如何實(shí)現(xiàn)js頁面切換功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-07-07
  • JS截取字符串 subStr()、substring()、slice() 方法示例詳解

    JS截取字符串 subStr()、substring()、slice() 方法示例詳解

    這篇文章主要介紹了JS截取字符串 subStr()、substring()、slice() 方法,本文通過示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-01-01
  • JavaScript 判斷瀏覽器是否支持SVG的代碼

    JavaScript 判斷瀏覽器是否支持SVG的代碼

    SVG(可縮放矢量圖形),接下來將介紹下如何判斷瀏覽器是否支持SVG,感興趣的朋友可以參考下哈,希望本代碼對(duì)你有所幫助
    2013-03-03
  • JavaScript打印iframe內(nèi)容示例代碼

    JavaScript打印iframe內(nèi)容示例代碼

    打印iframe內(nèi)容的方法有很多,下面為大家簡單介紹下使用JavaScript實(shí)現(xiàn)打印,有需求的朋友可以參考下
    2013-08-08
  • CSS3 動(dòng)畫卡頓性能優(yōu)化的完美解決方案

    CSS3 動(dòng)畫卡頓性能優(yōu)化的完美解決方案

    今天小編就為大家分享一篇關(guān)于css3 動(dòng)畫卡頓性能優(yōu)化的完美解決方案,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-09-09
  • 這段js代碼得節(jié)約你多少時(shí)間

    這段js代碼得節(jié)約你多少時(shí)間

    這段js代碼得節(jié)約你多少時(shí)間,學(xué)習(xí)js的朋友可以參考下。
    2011-12-12
  • 配置Webpack?SourceMap?實(shí)踐教程

    配置Webpack?SourceMap?實(shí)踐教程

    這篇文章主要介紹了如何配置Webpack?SourceMap,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-03-03
  • Javascript如何實(shí)現(xiàn)雙指控制圖片功能

    Javascript如何實(shí)現(xiàn)雙指控制圖片功能

    這篇文章主要介紹了Javascript如何實(shí)現(xiàn)雙指控制圖片功能,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02

最新評(píng)論