在输入字段中选择文件后浏览器冻结

Sil*_*ley 8 javascript performance firefox jquery google-chrome

我有一个包含输入文件字段 [ <input type="file" id="select-file" accept=".md"><label for="select-file">Select import file</label>]的表单。它为更改事件 [ $("#form").on("change", "#select-file", handler)]定义了一个 jQuery 处理程序,以便在我选择文件后立即触发。

它可以在 Linux 上使用 Firefox 在工作中完美运行,在家中使用 Firefox 和 Chrome在Windows上完美运行。

而在使用 Chrome 或 Firefox 的 Windows工作时,浏览器在选择文件后会冻结大约 8 秒。只有在此中断之后,我才能按下表单上的其他按钮,并且“更改”事件会触发。

放弃 Windows 和工作不啮合的假设,冻结似乎与工作中可用的不同网络磁盘有关。任何人都可以建议我必须检查的内容并希望有一种避免冻结的方法吗?谢谢!

小例子:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>File Select</title>
    <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
</head>
<body>
<div id="import-form">
    <input type="file" id="select-file" accept=".md">
    <label for="select-file">Select a file</label>
    <p id="selected-file">No file selected</p>
</div>
<script>
$("#import-form").on("change", "#select-file", function(e) {
    $("#selected-file").text(e.target.value.split('\\').pop());
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

小智 6

使用文件字段后,Chrome 会冻结几秒钟。

这是因为我在Windows资源管理器的“快速访问”菜单中有一个快捷方式。此快捷方式已链接到网络共享的文件夹。我已经删除了这个快捷方式,现在一切都很好。

  • 同样,如果您想删除它,在 Windows 10 上,单击“快速访问”图标(蓝色星),然后右键单击右侧面板“常用文件夹”面板中出现的死链接,然后选择“取消固定/删除”从快速访问”。应该没有错误消息。 (3认同)