大家用到input:file标签时,对于input:file的样式难看的处理方法一般有2种:

  1. 采用透明化input:file标签的方法,上面放的input:file标签,下面放的是其他标签,实际点击的还是上面的input:file标签,这种方法考验开发的样式水平了,不在细说
  2. 采用js去控制,触发input:file标签的click事件。这样就可以使用漂亮的图案来替换input:file的位置,代码如下:
 <html>
<head>
</head>
<body>
<input type="file" id="fileElem" style="display:none" >
<button href="#" id="fileSelect" onclick="openBrowse()">Select some files</button>
</body>
<script> function openBrowse(){
var ie=navigator.appName=="Microsoft Internet Explorer" ? true : false;
if(ie){ document.getElementById("fileElem").click(); }else{ var a=document.createEvent("MouseEvents");
a.initEvent("click", true, true);
document.getElementById("fileElem").dispatchEvent(a); }
}
</script> </html>

【JS】 伪主动触发input:file的click事件的更多相关文章

  1. 伪触发 input file 的click事件

    前端在做 input file 美化的时候,通常 把 input 定位position 到 已美化的按钮最上方 opacity: 0 HTML5时代,已有更方便的方法,点击美化按钮直接触发选择文件事件 ...

  2. 给js创建的一个input数组绑定click事件

    <html> <body> <input type="button" name="input[]" value="按钮1 ...

  3. 如何用按钮的click事件去触发a标签的click事件

    在jQquery中,可以用如下方式触发input.a标签的click事件: <input id="my_input" /> <a id="my_a&qu ...

  4. 主动触发input框的失去焦点事件,阻止输入法跳出

    今天遇到个问题,我在手机做一个选择生日的功能,但是当我点击input框时,事件选择插件和输入法都弹出来了,很丑,然后就想阻止输入法弹出来, 网上一个方法是:在input框的获取焦点事件里,主动触发失去 ...

  5. js jq 主动触发事件

    js的自定义事件与触发 //主动触发事件:触发鼠标被按下事件 var btn2 =document.getElementById("btn2"); var btn = docume ...

  6. JQuery的click,trigger触发a标签的click事件无效的问题分析

    今天在做一个手机端webAPP链接下载的时候,给a标签一个下载链接,但是通过 <a id="downFile" download="" href=&quo ...

  7. 使用jquery trigger 触发a标签的click事件取代window.open方法

    var ohtml='<div class="friend-dialog tac pt15 pb20">'+ '<div class="f-h32&qu ...

  8. echarts中的区域缩放组件dataZoom,主动触发选区缩放点击事件

    options设置 toolbox: { // 工具栏 feature: { dataZoom : { // 选时间缩放功能 show : true, // show为true时,才能触发takeGl ...

  9. 移动端触发touchend后阻止click事件

    // vue里面简单的处理方式,可以同时兼容PC和移动端 <div @touchend.stop.prevent="doSomething" @click.stop.prev ...

随机推荐

  1. openx _金额

    1/work/openx/lib/max/Delivery/log.php MAX_Delivery_log_logAdImpression    MAX_Delivery_log_logAdRequ ...

  2. Amazon AWS S3 操作手册

    Install the SDK The recommended way to use the AWS SDK for Java in your project is to consume it fro ...

  3. zabbix微信报警

    [root@LinuxS04 jiaoben]# ./weixin 联系人 baojing baojingok[root@LinuxS04 jiaoben]# pwd/usr/local/zabbix ...

  4. jsfl 改变舞台宽高

    fl.getDocumentDOM().height= 680; fl.getDocumentDOM().width= 550;

  5. UI5-文档-4.4-XML Views

    将所有UI放到index.html文件将很快导致一个混乱的设置,有相当多的工作在我们前面.我们先用sap.m.Text进行模块化.控件导入专用视图. SAPUI5支持多种视图类型(XML.HTML.J ...

  6. 【转】 关于寄存器ESP和EBP的一些理解

    原文: http://blog.csdn.net/zsJum/article/details/6117043 一直对寄存器ESP和EBP的概念总是有些混淆,查看定义ESP是栈顶指针,EBP是存取堆栈指 ...

  7. 使用Linux命令行测试网速-----speedtest-cli

    https://github.com/sivel/speedtest-cli 当发现上网速度变慢时,人们通常会先首先测试自己的电脑到网络服务提供商(通常被称为“最后一公里”)的网络连接速度.在可用于测 ...

  8. vim nginx配置文件时具备语法高亮功能

    1.下载nginx.vim 下载页面:http://www.vim.org/scripts/script.php?script_id=1886 wget http://www.vim.org/scri ...

  9. Linux逻辑卷的拉伸和缩小

    相对于普通磁盘优势是逻辑卷可以在线动态的拉伸(不用先unmount操作),只要vg中有足够的空间即可 1:首先查看vg是否有足够的空间 [root@gechong mapper]# vgdisplay ...

  10. 进化的Spark, 从DataFrame说起

    进化的Spark, 从DataFrame说起:http://www.tuicool.com/articles/IzeY7zM