效果图先给:

在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. Day10:关于桃子的和关于游戏新的设想(顺手做个记录孩子吃喝拉撒的工具)

    公历2015年6月3日~ 北京时间晚上8:42~ 在美中宜和~ 一个叫桃子的小美女出生了! 没错!小桃子终于出生了!真心不容易啊! 6月3日 03:00 AM 老婆推我,叫我起来,她说她肚子疼,还想上 ...

  2. jmeter之Xpath提取器

    首先创建线程组,添加http请求,具体的设置如图1所示: 图1 然后,再添加后置处理器中的XPath Extractor,具体的参数设置,以及表达式如图2: 图2 可以添加Debug PostProc ...

  3. NO29 用户提权sudo配置文件详解实践--志行为审计

     用户提权sudo配置文件详解实践: 放到visudo里:  验证权限:

  4. python-模块加密hashlib

    import hashlib# md5ybm_pwd='yuanbapqingsdfs234FF234HF@F' #m = hashlib.md5() #bytes_ybq = ybm_pwd.enc ...

  5. Unity游戏开发面试基础知识

    面试第一次知识总结: 一.Unity基本操作 1.unity提供哪几种光源? 点光源.平行光.聚光灯.区域光. 2.物体发生碰撞的必要条件什么? 两个物体必须有碰撞体Collider组件,一个物体上必 ...

  6. vue 【 子子组件 => 子组件 => 父组件 】 的事件和参数的传递

    1,子子组件  TodoItem.vue     <template>   <div class="todo-item" :class="{'is-co ...

  7. html5,css3炫酷实例-元素

    自动完成输入框下拉列表 使用的插件:jquery-ui 使用数据源实现文本框的自动完成功能 <link href="https://cdn.bootcss.com/jqueryui/1 ...

  8. canon 打印机 连接不上 netgear 路由器

    解决方法很简单,只要把信道设置到 10以内即可.

  9. pyhton读入Excel和csv数据文件

    pyhton读入Excel和csv数据文件#file 数据文件的输入输出操作(主要包括Excel表格和csv表格文件)import pandas as pd #pyhton读入数据必须要导入panda ...

  10. python scipy优化器模块(optimize)

    pyhton数据处理与分析之scipy优化器及不同函数求根 1.Scipy的优化器模块optimize可以用来求取不同函数在多个约束条件下的最优化问题,也可以用来求取函数在某一点附近的根和对应的函数值 ...