zoukankan      html  css  js  c++  java
  • js点击按钮实现文件上传

    点击按钮实现文件上传

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script src="./jquery.min.js" type="text/javascript"></script>
    <title>点击按钮实现文件上传</title>
    </head>
    <body>
    <input type="file" name="upload" id="upload" style="display: none;" />
    <input type="button" id="uploadFileButton" value="文件上传" />
    <br /><br /><span id="uploadFileName"></span>
    <script type="text/javascript">
    $('#uploadFileButton').click(function () {
    $('#upload').click();
    });
    $('#upload').click(function () {
    $('#upload').val('');
    });
    $('#upload').on('change', function(){
    var fileNameStr = $('#upload').val();
    var index2 = fileNameStr.length;
    if(fileNameStr.indexOf("/") != -1) {
    var index1 = fileNameStr.lastIndexOf("/");
    } else {
    var index1 = fileNameStr.lastIndexOf("\");
    }
    if (index1 <= -1) {
    index1 = 0;
    } else {
    index1 += 1;
    }
    fileNameStr = fileNameStr.substring(index1, index2);
    $('#uploadFileName').html(fileNameStr);
    });
    </script>
    </body>
    </html>
  • 相关阅读:
    Spring static 静态属性注入
    大众点评Cat--架构分析
    rxjava
    TCP/IP协议三次握手与四次握手流程解析
    [SDOI2014]数数
    CF-GYM101741K. Consistent Occurrences
    [JSOI2012]玄武密码
    [POI2000]病毒
    [JSOI2007]文本生成器
    [HNOI2006]最短母串问题
  • 原文地址:https://www.cnblogs.com/WebLinuxStudy/p/12784999.html
Copyright © 2011-2022 走看看