0
我已經完成了一個輸入來更改配置文件圖像,但我希望當我選擇一個新文件時,我的輸入會自動更改爲新圖像。在輸入選擇文件上顯示圖像
<div class="form-group" align="center">
<div style="position:relative; bottom:-90px; opacity:0.5; z-index:1; color:black;background:white;font-weight:bold">alterar</div>
<label style="display: block" for="avatar">
<img src="{{ $user->avatar }}" style="-moz-border-radius: 50px;border-radius: 50px;height: 80px" id="imgupload">
</label>
<div class="col-md-6">
<input type="file" class="form-control" name="avatar" id="avatar" style="display: none">
</div>
</div>
我不知道我該如何做到這一點。
編輯
我完成加入JS,但是當我選擇一個新的形象它改變了圓角的邊框..
JS:
function readFile() {
if (this.files && this.files[0]) {
var FR= new FileReader();
FR.onload = function(e) {
document.getElementById("imgupload").src = e.target.result;
};
FR.readAsDataURL(this.files[0]);
}
}
document.getElementById("avatar").addEventListener("change", readFile, false);
https://jsfiddle.net/gst96zax/
BTW中心已棄用使用 '的風格= 「文本對齊:中心」' – mlegg
「{{$用戶>頭像}}」 什針鋒相對是什麼?你使用角JS或其他東西? –
這就是圖像所在的網址.. – dante