【问题标题】:click() method firing twice on firefoxclick() 方法在 Firefox 上触发两次
【发布时间】:2014-02-28 23:59:50
【问题描述】:

我已经使用了这里描述的方法:

http://ericbidelman.tumblr.com/post/14636214755/making-file-inputs-a-pleasure-to-look-at

以编程方式从按钮控件触发文件输入框。它在 Chrome 和 IE 中运行良好,但在 Firefox 中打开文件上传窗口两次。

以下帖子看起来很相似,我尝试将 stopPropagation 添加到点击事件,但没有任何区别。

jQuery - .on('click', ...) event fires two times in Firefox

jQuery click event fired twice in firefox but not in IE

谢谢。

编辑

相关的HTML是:

<button type="button" id="load_slow_button">Load Playlist</button>
<input id="load_slow_list" type="file" onchange="load_list(this.id)">

按钮的相关Javascript是:

document.getElementById("load_slow_button").addEventListener('click', function(event) {
    document.getElementById("load_slow_list").click();
    event.stopPropagation;
}, false);

文件输入的 Javascript 是一个标准文件处理程序,当手动单击文件输入时可以正常工作。

【问题讨论】:

  • 请向我们展示您的代码
  • 代码已添加...

标签: javascript html firefox click


【解决方案1】:

通过将事件处理程序设置为命名函数来解决问题。

在窗口加载时运行的 init() 函数中:

document.getElementById("load_fast_button").addEventListener("click", process_click_fast, false);

然后是一个单独的命名函数中的事件处理程序:

function process_click_fast() {
    document.getElementById("load_fast_list").click();
}

我不知道为什么这可以解决问题,所以我很感激任何知道的人的来信!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 2014-01-08
    相关资源
    最近更新 更多