简体   繁体   English

使用 html 和 javascript 自定义上传文件

[英]Customize the Upload file using html and javascript

https://jsfiddle.net/yugxqopz/ https://jsfiddle.net/yugxqopz/

I am a newbie to UI world and I have a simple use case like我是 UI 世界的新手,我有一个简单的用例,比如

1) upload the document using choose file option 1) 使用选择文件选项上传文件
2) After it is chosen, I need to call a particular function in javascript like below 2)选择后,我需要在 javascript 中调用特定的 function ,如下所示

<form id="fileUploadForm" onsubmit="return uploadToTempFolder();" enctype="multipart/form-data">
    <input type="file" name="file" id="file" accept="application/pdf">
    <input type="submit" class="button-blue" value="Upload">
</form> 

Instead of choose file, I need to have an option like 'attach file' and once the user chooses the file, I don't need an extra upload button and I need to call the 'uploadToTempFolder'而不是选择文件,我需要有一个像“附加文件”这样的选项,一旦用户选择了文件,我就不需要额外的上传按钮,我需要调用“uploadToTempFolder”

Any help is appreciated.任何帮助表示赞赏。

Thanks,谢谢,
Harry哈利

you just need to put onchange event.你只需要放置 onchange 事件。

<form id="fileUploadForm" enctype="multipart/form-data">
    <input type="file" name="file" id="file" accept="application/pdf" onchange="uploadToTempFolder()">
</form> 

unfortunately we can not change the default text of file input but there is workaround.不幸的是,我们无法更改文件输入的默认文本,但有解决方法。

here is working example这是工作示例

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM