简体   繁体   English

用户从文件字段中选择文件时,是否发生JS事件?

[英]Is there a JS event that occurs when the user selects a file from a file field?

I would like to know if there is an event that I can call a JS function with that occurs when the user has selected a file for a file field. 我想知道是否有一个事件可以在用户为文件字段选择文件时调用JS函数。 Or is there something similar? 还是有类似的东西?

What I am trying to do is append the name of the file to the page once the user has selected the file, thanks. 我想做的是,一旦用户选择了文件,就将文件名追加到页面上。

when a user selects a file, the file input "changes", so you'll want to use the change event. 当用户选择文件时,文件输入“ changes”,因此您将要使用change事件。

$("#myinput").on("change",function(){
    console.log($(this).val());
})

http://jsfiddle.net/VeGpS/ http://jsfiddle.net/VeGpS/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发生某些事件时,从文档中删除JavaScript文件 - Remove javascript file from document when cetain event occurs 存储用户从文件输入中选择的文件路径作为会话变量,以便稍后重新填充该字段 - Storing the path of a file a user selects from the file input as a session variable to repopulate the field later 用户选择文件时执行javascript函数 - execute a javascript function when user selects a file 如何在dropzone.js中显示每个选定文件的选择字段 - How to show selects field with each selected file in dropzone.js 当用户从下拉列表中选择时,琐事问题/选择不会从 JSON 文件中填充 - Trivia Quuestion/Choices Not populating from a JSON file when user Selects from A Dropdown 用户选择文件->打印时,仅打印iframe的内容 - Printing only the contents of an iframe when a user selects file->print 当用户在 html 文件中选择一些文本时,执行 JavaScript function - Execute a JavaScript function when user selects some text in an html file 获取最终用户选择的文件的UNC - Get the UNC of a file that the end user selects 当用户选择并选择另一个文件时,如何防止 JavaScript 文件输入中的多个文件? - How to prevent multiple files in JavaScript file input when user chooses and selects another file? 当用户从弹出菜单中选择时,`onblur` 事件不会触发 - `onblur` event does not fire when user selects from the pop up menu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM