1. 多次选择相同的路径时,chooser.onchange 事件不触发
Choosing the same directory multiple times
Once the chooser has been used to select a directory (or the same file path + file name), the change event will not fire again since the value of the input is already set with the same value. For example, if a user is expected to select a directory to export a file to, if they choose the same directory multiple times, the change event will one fire once. This is only an issue if the selected value may potentially be the same multiple times, i.e. in the case of selecting an output directory.
In this case, re-setting the value of the input can ensure that the change event will always fire in subsequent selections.
jQuery
<script>
function chooseFile(name) { var chooser = $(name); chooser.change(function(evt) { console.log($(this).val()); // Reset the selected value to empty ('') $(this).val(''); }); chooser.trigger('click'); } chooseFile('#fileDialog'); </script>
本文探讨了在多次选择相同目录时,文件选择器的onchange事件不触发的问题,并提供了一种解决方案,通过重新设置输入框的值为空确保事件始终被触发。

478

被折叠的 条评论
为什么被折叠?



