zoukankan      html  css  js  c++  java
  • input type="file"获取文件名方法

    文件上传比较丑,样式调整时会有一个获取文件名,或者包含文件路径的文件名的方法

    html代码

        <div class="file-box"> 
    	<form id="uploadForm"> 
    		<input type="text" id="textfield" class="txt" />
    		<input type="button" class="btn" value="浏览..." /> 
    		<input type="file" name="file" class="file" id="fileField" onchange="document.getElementById('textfield').value=this.files[0].name"/> 
    		<input type="submit" class="btn" value="上传" /> 
    	</form> 
    </div>
    

    CSS样式

    .file-box{ position:relative;340px;margin:20px;}
    .txt{ height:28px;line-height:28px; border:1px solid #cdcdcd; 180px;}
    .btn{70px; color:#fff;background-color:#3598dc; border:0 none;height:28px; line-height:16px!important;cursor:pointer;}
    .btn:hover{background-color:#63bfff;color:#fff;}
    .file{ position:absolute; top:0; right:85px; height:30px;line-height:30px; filter:alpha(opacity:0);opacity: 0;254px }

    效果图

    只获取文件名

    document.getElementById('fileField').files[0].name

    获取带路径的文件名

    document.getElementById('fileField').value

  • 相关阅读:
    JSON的使用总结
    pc端分页插件的使用
    简单修改选择文件样式
    H5中的本地存储
    H5中的 meta 标签及 移动页面单位
    1001. A+B Format (20)
    查看mysql的注册表路径
    win10 64位安装mysql
    [POLITICS] S Korea lawmakers vote to impeach leader
    5-17 Hashing (25分)
  • 原文地址:https://www.cnblogs.com/midnight-visitor/p/8992121.html
Copyright © 2011-2022 走看看