It has been a long time since javascript was not used as a page. On this day, a friend suddenly asked me about the FileUpload assignment problem, because after FileUpload is compiled, the <input type = "file"/> tag is generated. In the HTML document, <input type = "file"/>
The tag is used by the browser to send the selected file to the server. This element has a value
Attribute, stores the name of the file specified by the user. For security reasons, the value Attribute of the file tag is read-only and cannot be modified by programmers.
The property is also ignored. Therefore, when the database records the address of the file on the client and needs to assign values to the value attribute of the file tag, the problem may occur.
After a multi-flip query, we decided to use the "Hide tag" method to implement these functions. First, add a text tag, a button tag, and a file tag on the page, and set the sytle attribute of the file tag to "visibility: hidden; "simulate the appearance of the text tag and the button tag. In the window. onload event, the existing file path is displayed on the text tag. In The onclick method of the button tag, the file tag click event is triggered to obtain the uploaded file, and the path of the uploaded file is displayed on the text tag.
<Html xmlns = "http://www.w3.org/1999/xhtml">
Note that the above method only applies to assigning values to the name attribute of the file tag, but cannot directly obtain the file Upload file. This is because of security. the browser will prevent the file from being uploaded directly by binding the file tag through the program. If you want to directly upload files by hiding tags, it takes a little time. First, create a file tag, add a text tag to overwrite the text of the file, and assign a value to the text tag in the onchange event of the file.
<Html xmlns = "http://www.w3.org/1999/xhtml">