国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JS實現瀏覽上傳文件的代碼

2019-11-19 15:42:03
字體:
來源:轉載
供稿:網友

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:

<div style="position:relative;width:380px;">      <iframe id="t_load" name="t_load" style="display: none"></iframe>      <form action="" method="post" enctype="multipart/form-data" name="form1" target="t_load">        <input type='text' name='textfield' id='textfield' style="height:22px; border:2px solid #cdcdcd; width:230px; border-radius:50px;" />        <input type='button' value='瀏覽...' style="display: inline-block; margin-bottom: 0; font-size: 14px; border-radius: 4px;padding: 6px 12px; margin: 2px 2px; border: 1px solid #357ebd; background: #1b9ad5; color: #fff;" />        <input type="file" name="file1" accept="image/jpeg, image/gif" id="file1" onchange="document.getElementById('textfield').value=this.value" style="position:absolute; top:5px; right:74px; height:27px; filter:alpha(opacity:0);opacity: 0;width:300px" />        <input type="button" name="button" onclick="mysubmit()" value="上傳" style="display: inline-block; margin-bottom: 0; font-size: 14px; border-radius: 4px;padding: 6px 12px; margin: 2px 2px; border: 1px solid #357ebd; background: #1b9ad5; color: #fff;">      </form>    </div>    <div style="display:none;color:#6D6D72;font-size: 20px;" id="res"></div>    <script>      function mysubmit() {        var a = document.getElementById("textfield").value;        if(a == "") {          alert("請上傳文件");          return;        }        document.form1.submit();        ajaxsend();      }      function ajaxsend() {        var xmlHttp;        if(window.ActiveXObject) {          xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");        } else {          xmlHttp = new XMLHttpRequest();        }        xmlHttp.open("post", "upload", true);        xmlHttp.onreadystatechange = function() {          xmlHttp.readyState;          if(xmlHttp.readyState == 4) {            res.innerHTML = "上傳成功!";            setTimeout(function() {              res.innerHTML = "";            }, 2000);          } else {            document.getElementById("res").style.display = "inline";          }        }        xmlHttp.send();        var obj = document.getElementById('textfield');        obj.outerHTML = obj.outerHTML;      }    </script>

總結

以上所述是小編給大家介紹的JS實現瀏覽上傳文件的代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 呼和浩特市| 固始县| 赤水市| 屏山县| 彝良县| 荣昌县| 宾阳县| 嘉善县| 黑水县| 高青县| 华坪县| 繁峙县| 都昌县| 舞钢市| 兰州市| 西乡县| 涞水县| 屏边| 中卫市| 视频| 长海县| 托克托县| 交城县| 天镇县| 晋宁县| 浠水县| 逊克县| 商洛市| 绥中县| 鄄城县| 沙雅县| 冀州市| 浙江省| 乐陵市| 兴宁市| 马尔康县| 福建省| 西安市| 环江| 普洱| 东台市|