【问题标题】:jQuery: “change” event on file input element does not fire in IE but working in ChromejQuery:文件输入元素上的“更改”事件不会在 IE 中触发,但在 Chrome 中有效
【发布时间】:2016-08-30 15:39:38
【问题描述】:

我有文件输入元素被点击,但在选择文件后,更改事件不会在 Internet Explorer 中触发,但它在 Chrome 中工作正常。

下面是我的代码

file_upload = '<input type="file" id="FileUpload" name="FileUpload" class="btn btn-default fileUploadReader"/>';

$("#FileUpload").change(function () {
    alert("Change Event");
});

【问题讨论】:

  • 你用的是哪个版本的IE?
  • 我已经找到了解决方案。谢谢!
  • 听起来不错!祝你好运
  • 那么解决方案是什么?
  • @shivanisurana 解决方案是什么

标签: javascript jquery html


【解决方案1】:

问题在于,在 Internet Explorer 中,单选按钮上的 .change() 事件没有被正确触发,或者至少它的行为与其他浏览器中的行为不同。

但是有一个相对简单的方法可以解决这个问题,即处理 .click() 事件,然后,只需 .blur().focus() 控制 - 这将导致 change() 事件解雇:

$(document).ready(function() {
  $('#FileUpload').click(function () {
        // Cause the change() event

        this.blur();

        this.focus();
   });
  $('#FileUpload').change(function() {

    // Handle .change() event as normal....

  });

});

【讨论】:

    猜你喜欢
    • 2023-03-13
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 1970-01-01
    • 2013-12-20
    • 1970-01-01
    相关资源
    最近更新 更多