HTML:

  <input type="file" style="display:none" id="addfile-btn">

  <div onclick="addfile()">点击上传图片</div>

JS:

  <script>

   function addfile() {

    document.getElementById("addfile-btn").click();

   }

  </scrip>

如果一个页面需要多个这种事件的话,显然用ID是不太好的,那么就可以通过jQuery的prev来实现同级class查找,以此实现上传控件的调用。

HTML:

<input type="file" style="display:none" class="addfile-btn">

<div class="upload">点击上传图片1</div>

<div class="upload">点击上传图片2</div>

JS:

<script>

$(".upload").bind('click', function() {

$(this).prev(".addfile-btn").click();

});

</script>

隐藏<input type="file"> 实现点击div或图片打开文件选择路径的更多相关文章

  1. 上传文件 隐藏input type="file",用text显示

    <div> <span>上传文件:</span> <input type="file" id="upload_file" ...

  2. 利用jquery来隐藏input type="file"

    <li> <input type="text" name="token" value = "<?php ech$_SESSIO ...

  3. jquery的input:type=file实现文件上传

    <!DOCTYPE html> <html> <head> <title>html5_2.html</title> <style> ...

  4. <input type="file">如何实现自定义样式

    利用样式覆盖来实现效果:先看下原本和改变后的样式 1 <!doctype html> 2 <html> 3 <head> 4 <title>file自定 ...

  5. input type=file accept中可以限制的文件类型

    在上传文件的时候,需要限制指定的文件类型. <input type="file" accept="image/*" /> accept表示可以上传文 ...

  6. input type=file accept中文件格式限制

    原文链接:https://blog.csdn.net/usuallyuser/article/details/83060341 accept="application/msexcel,app ...

  7. <input type="file"> 标签详解

    详见:https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/Input/file#attr-multiple 使用 type=" ...

  8. 自定义上传按钮 <input type="file" name = "file"/> (将file隐藏在button下)

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

  9. python+selenium:解决上传文件<input type='file'>标签属性被css的visibility隐藏导致无法定位元素的问题

    要想上传文件,需要找到在HTML中<input type="file" />这个标签,有它就可以利用send_keys上传文件,不过这里的<input>元素 ...

随机推荐

  1. Centos7下搭建LAMP平台环境

    1.启用Apache2 Centos7默认已经安装httpd服务,只是没有启动.如果你需要全新安装,可以yum install -y httpd 启动服务:systemctl start httpd. ...

  2. Ngui 五种点击事件实现方式及在3d场景中点透的情况

    http://www.unity蛮牛.com/thread-22018-1-1.html ngui作为unity界面插件之一中,无疑是最好用,使用最多的了从自学unity到现在界面一直使用它 由于它的 ...

  3. php服务端写日志文件

    1.需求 在服务端记录日志 2.基础版 最基础的文件读写,(要注意window和linux的换行符,window是\r\n,linux是\n),这里就写入一个时间. <?php $handle ...

  4. (备忘)android清单文件中<meta-data>标签,以及<intent-filter>下的<data>标签及其他标签

    1.metadata可以写在application下也可以写在activity下,作为全局或activity内共享的数据 以键值对形式保存 <meta-data android:name=&qu ...

  5. django xadmin 插件(3) 列表视图新增自定义按钮

    效果图: 编辑按钮是默认的list_editable属性对应的插件(xadmin.plugins.editable) 放大按钮对应的是自定义插件. 自定义按钮源码: xplugin.py(保证能够直接 ...

  6. ffmpeg解码音频流

    //初始化.注册编解码器 avcodec_init(); av_register_all(); avformat_network_init(); //选取测试文件 char* FileName=&qu ...

  7. IIS 处理请求 原理

    有时候我们会发现当我们访问一个IIS网站时,使用网址可以正常访问,但是使用IP却不行,这是什么原因呢? 原来IIS可以使用一个IP地址和端口绑定多个网站,这些网站的IP地址与端口都一样,因此在客户端或 ...

  8. Smallest Rectangle Enclosing Black Pixels

    An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...

  9. struts2 模型驱动

    public class User3Action extends ActionSupport implements ModelDriven<User> { private User use ...

  10. 如何为自己的windows 8系统的电脑更换锁屏壁纸

    现在的人都喜欢个性,今天教大家如何设置自己想要的锁屏壁纸 工具/原料 Windows 8系统的笔记本电脑 方法/步骤   将鼠标移到电脑的右下方,点击设置按钮进入设置页面   找到更改电脑设置并点击进 ...