触发器单击事件在IE10中不工作 [英] Trigger click event not working in IE10

查看:115
本文介绍了触发器单击事件在IE10中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为图片添加 onclick 事件,所以当我点击图片时,会触发文件打开对话框。但它不工作在IE10。



  $(#button)。on(click,function(){$(#upload)。 click;;;});  

  #upload {opacity: 0;}  

 < script src =https: /ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js\"> ;</script><img id =buttonsrc =http://www.kafkabrigade.org .uk / wp-content / uploads / 2011/07 / button-pic.jpg/>< input id =uploadtype =file>  

解决方案

IE9,IE10,IE11。

 < script src =https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js>< / script> 
< input type =file/>
< img id =buttonsrc =http://www.kafkabrigade.org.uk/wp-content/uploads/2011/07/button-pic.jpg/>



jQuery

  $('#button')。click(function(){
$('input [type = file]')。trigger('click');
});

$('input [type = file]')。change(function(){
$('input [type = text]')。 ());
});

CSS

  input [type = file] {
display:block;
height:0;
width:0;
}

工作DEMO


I need to add onclick event to an image so when I click on the image it will trigger the file open dialog. But it doesn't work in IE10.

$("#button").on("click",function(){
  $("#upload").trigger("click");
});

#upload{
  opacity: 0;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img id="button" src="http://www.kafkabrigade.org.uk/wp-content/uploads/2011/07/button-pic.jpg" />

<input id="upload" type="file" >

解决方案

Ok, I tested this in the newest FF, Opera, Chrome, IE8, IE9, IE10, IE11. Its working everywhere.

HTML:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="file" />
<img id="button" src="http://www.kafkabrigade.org.uk/wp-content/uploads/2011/07/button-pic.jpg" />

jQuery:

$('#button').click(function() {
    $('input[type=file]').trigger('click');
});

$('input[type=file]').change(function() {
    $('input[type=text]').val($(this).val());
});

CSS:

input[type=file] {
    display: block;
    height: 0;
    width: 0;
}

Working DEMO

这篇关于触发器单击事件在IE10中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆