我正在嘗試上傳照片並在<img>
中顯示,但它不起作用。 我正在使用Python和Django框架以及用戶需要的自動生成表單。 我的JavaScript代碼是從Here用javascript上傳和預覽圖像
這裏是我的代碼,JavaScript和也HTML:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#myimg').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#photoinput").change(function(){
readURL(this);
});
<form id="form1" runat="server">
<div name="imageholder" class="row tm-image-holder">
<div class="col-md-12" style="text-align: center">
<img id="myimg" src="#" style="height: 200px;text-align: center;">
</div>
</div>
<input id="photoinput" type="file" name="photo" href="#"
class="btn btn-block btn-lg btn-primary inout-margin mybut">
<input id="name" name="name0" type="text" class="add-input input-margin"
placeholder="Name, Mohammad, ... *">
<input id="job" name="job0" type="text" class="add-input"
placeholder="Job, Developer, Designer, ... *">
<textarea id="explain" name="explain0" class="add-textarea input-margin" rows="4"
placeholder="Explain this member in 2 to 4 lines *"></textarea>
</form>
是否有錯誤消息?你包括jQuery? – epascarello
不,它不顯示任何在 –
添加名稱圖像,並嘗試訪問