问题
Basically what im looking for is a way for the user to upload an html file when they click
<input type="file"/>
button.
When the user selects an HTML file, I want to take the HTML code and place it within a div. Can this be done without server-side languages?
回答1:
Using javascript You cannot browse on a clients disk files. However your case is possible. Please check the below stackover question which exactly matches your requirement. Refer Paolo Moretti answer. Here is the link: How to open a local disk file with Javascript?
As you want to browse/upload only HTML files add "accept" to your input file type like this:
<input type="file" accept="text/html"/>
In HTML5 you can use file extensions as the accept like this:
<input type="file" accept=".html"/>
来源:https://stackoverflow.com/questions/27154409/js-submit-html-file-and-place-file-code-within-div