我想使用Html和Javascript上传文件。我怎么能够 ? [英] I Want To Upload A File Using Html And Javascript Only. How Can I ?

查看:67
本文介绍了我想使用Html和Javascript上传文件。我怎么能够 ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想只使用html和javascript上传文件。我怎么办?

i want to upload a file using html and javascript only. how can i ?

推荐答案

根本不需要使用JavaScript。你需要 form 元素,其元素为submit和file(带有 type 属性的输入元素)这些价值观)。其中一个将允许用户选择要提交的本地文件,并且提交按钮将发起HTTP请求。



请参阅:

http://www.w3schools.com/html/html_form_elements.asp [ ^ ],

http://www.w3schools.com/tags/tag_input.asp [ ^ ]。



你可以找到一个包含所有这三个的简单样本元素,例如,这里: https://www.cs.tut.fi/~jkorpela/forms /file.html [ ^ ]。







另外,有可能使用AJAX发送任何可想到的HTTP请求,但是对于这个简单的情况,发送文件太麻烦了,而另一方面,这是一个巨大的过度杀伤力。一般情况下请参阅: http://en.wikipedia.org/wiki/Ajax_(programming) [ ^ ]。



-SA
No need to use JavaScript at all. You need to have form element with input elements of the types "submit" and "file" (with type attributes with these values). One of them will allow the user to select a local file to submit, and submit button will initiate an HTTP request.

Please see:
http://www.w3schools.com/html/html_form_elements.asp[^],
http://www.w3schools.com/tags/tag_input.asp[^].

You can find a simple sample with all three of these elements, for example, here: https://www.cs.tut.fi/~jkorpela/forms/file.html[^].



Alternatively, it's possible to send any thinkable HTTP request using AJAX, but for this simple case, it would be too tricky to send a file, and from the other hand, a huge overkill. Please see, for general understanding: http://en.wikipedia.org/wiki/Ajax_(programming)[^].

—SA


这篇关于我想使用Html和Javascript上传文件。我怎么能够 ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆