我有以下代碼來上傳照片。我目前有這個過程集,所以點擊提交按鈕就可以上傳。如何在不提交按鈕的情況下自動上傳該代碼?由於腳本上傳文件時未提交
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