這是我的問題,我有這個小代碼來顯示img,我沒有重新加載LIVE上傳,但它只適用於一個img,因爲readURL(input)
沒有類和直接從noname輸入,當我添加一個類readURL(input.joint)
,它會降低錯誤!這裏是我的代碼:使用FileReader選擇並顯示圖像
<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>
我需要添加一些id或類到這個jquery函數,使其獨特的每個輸入。
我想要做的事:
<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>
這不是非常清楚你想要做什麼。你得到的錯誤是什麼? – Jivings
錯誤我的意思是什麼都沒有工作:(對不起我的英文,也許我不能正確解釋我的問題!輸入功能需要與id或類 – user2784722
你期待從這裏:'readURL(input.joint)'? – Jivings