这是我的问题,我有这个小代码来显示我正在上传 LIVE 而不重新加载的 img,但它只适用于一个 img,因为readURL(input)
没有类并且直接从 noname-input 工作,当我添加一个类readURL(input.joint)
,它丢弃错误!这是我的代码:
<input class="joint" type='file' id="imgInp" />
<img style="width:45px" id="blah" src="#" alt="your image" />
<script type="text/javascript">
function readURL(input) {
if (input.filers && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
</script>
我需要向这个 jquery 函数添加一些 id 或类,以使其对每个输入都是唯一的。
我正在尝试做的事情:
<input class="joint" type='file' id="imgInp" />
<img style="width:45px" id="blah" src="#" alt="your image" />
<script type="text/javascript">
function readURL(input.joint) {
if (input.joint.filers && input.joint.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.joint.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
</script>
<input class="file2" type='file' id="imgInp" />
<img style="width:45px" id="blah" src="#" alt="your image" />
<script type="text/javascript">
function readURL(input.file2) {
if (input.file2.filers && input.file2.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.file2.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
</script>