87,909
社区成员
发帖
与我相关
我的任务
分享
<form>
<input type="file" id="fls" multiple onchange="upload(this)"/>
</form>
<script>
function xhrupload(fd, url) {
var xhr = new XMLHttpRequest();
xhr.open("post", url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (200 == xhr.status) {
alert(xhr.responseText);
}
else alert('发生错误\nstatus:' + xhr.status + '\n返回内容:' + xhr.responseText);
}
}
xhr.send(fd);
}
function upload(fls) {
for (var i = 0; i < this.files.length; i++) {
var fd = new FormData();
fd.append("file", fls.files[0]);
xhrupload(fd, '上传地址');
}
}
</script>