1
我试图做一个更改事件触发每次文件输入更改, 现在我试图清除值,每次它的工作,但第一次,但当用户更改文件字段readURL(输入)不运行的secound时间。为什么?.change事件只是第一次启动
HTML
<input type='file' id="imgInp" onclick="readURL(input)" />
的JavaScript
$("#imgInp").change(function(){
readURL(this);
ClearFileUpload();
});
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
ClearFileUpload();
reader.onload = function (e) {
photo.innerHTML='<img src="' + e.target.result + '" width="400" />';
}
reader.readAsDataURL(input.files[0]);
}
}
function ClearFileUpload() {
document.getElementById("photo").innerHTML="";
var photo = document.getElementById('photo');
var photoinput = document.getElementById('imgInp');
if (photoinput != null) {
document.getElementById('imgInp').outerHTML = photoinput.outerHTML;
}
document.getElementById("name").innerHTML="";
}
我已经试过。对( '输入'),但这不火,
感谢那些伟大的工作!!!! – user3637210
@ user3637210:很高兴它有帮助 –