效果图先给:

在html中涉及到文件选择的问题,文件选择使用

 input(class="filter_input form-control" type="file)

但是在不同的浏览器中,该input显示是有很大的问题的

这是在IE中,挺正常的

在Edeg中,就有点丑了

在Google中,简直无法忍受

所以,正文开始:

Html代码先添加一个input type为file  并设置隐藏,用一个readonly的input占用它的位置,在其后加一个button

<div style="margin-bottom:20px" class="row row_space">
<div style="padding-right:0px" class="col-xs-1">
<label for="">Choose File</label>
</div>
<div style="padding-left:0px">
<div class="col-xs-4">
<input style="display:none" type="file" onchange="importExcel(this)" id="file_path" class="filter_input form-control"/>
<input readonly="readonly" type="text" onclick="Browser()" id="_file_path" class="filter_input form-control"/>
</div>
<div class="col-xs-1">
<button id="batch_btn_compile" onclick="Browser()" class="btn btn-primary">Browser</button>
</div>
</div>

设置Browser()事件触发第一个input的click事件(打开资源管理器选择文件,这是不需要编写的,自带)

function Browser()
{
$('#file_path').click();
}

当选择某文件后,会触发第一个input的onchange事件,将取到的文件名赋值给第二个input框

function importExcel(obj) {
$('#_file_path').val(obj.files[0].name);
...
}

注:只能取到文件名,文件路径可能出于保护用户隐私的问题未取到,如果有人能取到请评论指正,谢谢

对input type=file 修改样式的更多相关文章

  1. 自定义input[type="file"]的样式

    input[type="file"]的样式在各个浏览器中的表现不尽相同: 1. chrome: 2. firefox: 3. opera: 4. ie: 5. edge: 另外,当 ...

  2. html中,文件上传时使用的<input type="file">的样式自定义

    Web页面中,在需要上传文件时基本都会用到<input type="file">元素,它的默认样式: chrome下: IE下: 不管是上面哪种,样式都比较简单,和很多 ...

  3. input[type="file"]的样式以及文件名的显示

    如何美化input[type="file"] 基本思路是: (1)首先在 input 外层套一个 div : (2)将 div 和 input 设置为一样大小(width和heig ...

  4. html中input type=file 改变样式

    <style> #uploadImg{ font-size:12px; overflow:hidden; position:absolute} #file{ position:absolu ...

  5. html input[type=file] css样式美化【转藏】

    相信做前端的都知道了,input[type=file]和其他输入标签不一样,它的事件必须是在触发自身元素上,而不能是其他元素.所以不能简单的把input隐藏,放个button上去. <a hre ...

  6. input[type='file']默认样式

    <input type="file" name="" id="" value="" /> 当input的ty ...

  7. input[type='file']样式美化及实现图片预览

    前言 上传图片是常见的需求,多使用input标签.本文主要介绍 input标签的样式美化 和 实现图片预览. 用到的知识点有: 1.input标签的使用 2.filelist对象 和 file对象 3 ...

  8. input[type=file]样式更改以及图片上传预览

    以前知道input[type=file]可以上传文件,但是没用过,今天初次用,总感觉默认样式怪怪的,想修改一下,于是折腾了半天,总算是小有收获. 以上是默认样式,这里我想小小的修改下: HTML代码如 ...

  9. 更改input【type=file】样式

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

随机推荐

  1. JAVA虚拟机:内存回收策略及算法

    java虚拟机中的程序计数器区.虚拟机栈区.本地方法栈区3个区域是随着线程的创建而创建,随着线程的结束而结束时,内存自然得到回收,所以这三个区域不需要过多考虑内存的回收问题. java虚拟机中的方法区 ...

  2. 吴裕雄--天生自然JAVA数据库编程:处理大数据对象

    import java.sql.Connection ; import java.sql.DriverManager ; import java.sql.SQLException ; import j ...

  3. greenplum 存储过程 索引信息

    涉及的索引表 参考:http://blog.nbhao.org/1539.html pg_index pg_indexes pg_stat_all_indexes # 记录当前数据库中所有的索引的使用 ...

  4. GNS3 模拟免费ARP

    R2 : conf t int f0/0 no shutdown ip add 192.168.1.254 255.255.255.0 end R1 : conf t int f0/0 no shut ...

  5. Unix-Time

    1. Unix_time 2. Year_2000_problem 3. Year_10,000_problem 4. Year_2038_problem 5. Time_formatting_and ...

  6. java执行操作系统脚本

    http://www.cnblogs.com/bencakes/p/6139477.html 以前只是知道Runtime.getRuntime().exec(command);这种用法,但是有时候命令 ...

  7. hbase hbck及region RIT处理

    hbase hbck主要用来检查hbase集群region的状态以及对有问题的region进行修复. hbase hbck :检查hbase所有表的一致性,如果正常,就会Print OK hbase ...

  8. VUE- 访问服务器端数据 axios

    VUE- 访问服务器端数据 axios 一,安装 npm install axios 二,在http.js中引入 import axios from 'axios'; 三,定义http request ...

  9. https://blog.csdn.net/yyoinge/article/details/81557604

    https://blog.csdn.net/yyoinge/article/details/81557604 http://www.mamicode.com/info-detail-2346464.h ...

  10. #pragma命令详解

    每种C和C++的实现支持对其宿主机或操作系统唯一的功能.例如,一些程序需要精确控制超出数据所在的储存空间,或着控制特定函数接受参数的方式.#pragma指示使每个编译程序在保留C和C++语言的整体兼容 ...