我有以下代码来上传照片。我目前有这个过程集,所以点击提交按钮就可以上传。如何在不提交按钮的情况下自动上传该代码?由于脚本上传文件时未提交
HTML:
<form data-ajax="false" id="imageform" action="imageup.php" method="POST" enctype="multipart/form-data" name="form">
<a id="companylink" href="">
<div id="yourBtn" onclick="getFile()" onchange="readURL(this);">
<img id="companyprofileimg" src="image/<?php echo $row['photo']?>"/>
</div>
<span id="cetext"><?php echo $row['username']?></span>
</a>
<div style='height: 0px;width: 0px; overflow:hidden;'>
<input id="upfile" type="file" value="upload" name="file" onchange="readURL(this);"/>
</div>
<a data-theme="g" data-ajax="false" data-role="button" id="imagesub" onclick="$('#imageform').submit();" aria-disabled="false">Upload Image</a>
</form>
JAVASCRIPT:
function getFile(){
document.getElementById("upfile").click();
}
function sub(obj){
var file = obj.value;
var fileName = file.split("\\");
document.getElementById("companyprofileimg").innerHTML = fileName[fileName.length-1];
document.myForm.submit();
event.preventDefault();
document.getElementById('imageform').submit();
}
我编辑了我的代码。你能给我一个关于新代码的解决方案吗?我摆脱了readURL功能,这是不需要的。谢谢。 – Steven 2013-02-16 16:46:33
@Steven:另请检查此[链接](http://stackoverflow.com/questions/2320069/jquery-ajax-file-upload)和[链接](http://stackoverflow.com/questions/166221/how- can-i-upload-files-asynchronously-with-jquery)如果你想要一个像AJAX一样的体验 – user1428716 2013-02-16 16:52:19
@ user1428716看起来不错,但是这两者仍然需要点击一个提交按钮。 – Steven 2013-02-16 16:59:20