【问题标题】:.change acting weird in IE9.change 在 IE9 中表现怪异
【发布时间】:2012-02-08 06:33:27
【问题描述】:

所以我有一个这样的表单提交设置

<button>edit a photo</button>
<form style="visibility: hidden;">
  <input type="file" id="file" name="file" val=""/>
  <input type="submit" name="submit">
</form>

我的 javascript 看起来像这样

$("#edit-button").click(function() {
  $("#file").click();
});

$("#file").change(function() {
  //submit form
});

起初我以为 IE9 可能无法识别来自 Jquery 的 .change 事件,但是我注意到如果取消隐藏我的表单并直接单击它,则会触发更改功能。如果我使用编辑按钮来激活浏览,那么即使更改了 .change 也不起作用。

我猜当我单击文件输入的“浏览”按钮时,它不会像 $("#file").click() 那样被读取。有谁知道解决这个问题的方法吗?

【问题讨论】:

    标签: jquery forms internet-explorer-9 submit


    【解决方案1】:

    猜测这是因为您的处理程序没有被绑定到不可见的表单(有时就是这种情况)。

    试试:

    // document or some other container
    $(document).on("change", "#file", function () {
        //submit form
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-03
      • 2020-01-04
      • 2022-12-11
      • 2012-01-18
      • 2012-10-10
      • 2011-09-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多