祝大家聖誕快樂。將圖片上傳到圖片標籤
我有4個部分,每個部分都包含一個空的img標籤。在上傳圖片時,它必須適合相應的部分。
當我點擊「在第1部分添加圖片」並上傳圖片時,它必須在Image_1 div中修復,就像明智的所有四個一樣。但是,當我插入點擊功能在我的代碼它不工作。
這是什麼我的錯誤。
<div class="pre_img" >
<span>
<img class="prw_img" src="http://www.iconshock.com/img_jpg/REALVISTA/general/jpg/128/preview_icon.jpg" alt="your image" />
</span>
</div>
<input id="file" type="file" name="files[]" onChange="readURL(this);" />
<div id="Image_1">
<button> AddImage to section 1</button>
<img id="img_1" alt="" width="100px" height="100px" style="Border 1px solid #ccc"/>
</div>
<div id="Image_2">
<button> AddImage to section 2</button>
<img id="img_2" alt="" width="100px" height="100px" style="Border 1px solid #ccc"/>
</div>
<div id="Image_3">
<button> AddImage to section 3</button>
<img id="img_3" alt="" width="100px" height="100px" style="Border 1px solid #ccc"/>
</div>
<div id="Image_4">
<button> AddImage to section 4</button>
<img id="img_4" alt="" width="100px" height="100px" style="Border 1px solid #ccc"/>
</div>
繼承人我的腳本
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('.prw_img,#img_1').attr('src', e.target.result).width(112).height(112);
$('#img_1').css('display','inline');
};
reader.readAsDataURL(input.files[0]);
}
}
我已經做了JSBIN爲了便於理解,我 加沒有帶一個點擊嘗試添加該功能,那麼整個腳本不工作
我只是檢查,它正在爲SECTION1僅 – Satya
雅我在劇本中只提到#img_1 ....我必須點擊旁邊的按鈕,然後上傳圖片該節 –
你離開上面的示例代碼中的表單元素?否則,你錯過了標記的重要組成部分... –