How to set a value to a file input in HTML?

前端 未结 8 2964
天命终不由人
天命终不由人 2020-11-21 04:45

How can I set the value of this?


8条回答
  •  南旧
    南旧 (楼主)
    2020-11-21 05:15

    Not an answer to your question (which others have answered), but if you want to have some edit functionality of an uploaded file field, what you probably want to do is:

    • show the current value of this field by just printing the filename or URL, a clickable link to download it, or if it's an image: just show it, possibly as thumbnail
    • the tag to upload a new file
    • a checkbox that, when checked, deletes the currently uploaded file. note that there's no way to upload an 'empty' file, so you need something like this to clear out the field's value

提交回复
热议问题