|
 |
|
สอบถามเรื่องการลบ Input type="file" รูปหน่อยครับ พอดีอยากจะให้ผู้ใช้ลบ Input type="file" รูปในกรณีคลิกมาเกินอ่ะครับ |
|
 |
|
|
 |
 |
|
สอบถามเรื่องการลบ Input type="file" รูปหน่อยครับ พอดีอยากจะให้ผู้ใช้ลบ Input type="file" รูปในกรณีคลิกมาเกินอ่ะครับ
อยากจะให้มีปุ่มกากบาท ลบรูปอ่ะครับไม่ทราบว่าต้องเพิ่มคลิก เหตุการณ์ตรงไหนครับ
ขอบคุณครับ
ตัวอย่าง Sourcode เอามาจากเว็บนี้ครับ
https://www.formget.com/upload-multiple-images-using-php-and-jquery/

html)
<div id="filediv">
<input name="file[]" type="file" id="file"/>
</div>
<br/>
<input type="button" id="add_more" class="upload" value="Add More Files"/>
script.js
var abc = 0; //Declaring and defining global increement variable
var counter = 0;
var wrapper = $(".input_fields_wrap");
$(document).ready(function() {
$('#add_more').click(function() {
counter = counter+1;
if(counter<=9){
$(this).before($("<div/>", {id: 'filediv'}).fadeIn('slow').append(
$("<input/>", {name: 'file[]', type: 'file', id: 'file'}),
$("<br/><br/>")
));
}else{
alert("รูปเกิน 10 รูป");
e.preventDefault();
}
});
//following function will executes on change event of file input to select different file
$('body').on('change', '#file', function(){
if (this.files && this.files[0]) {
abc += 1; //increementing global variable by 1
var z = abc - 1;
var x = $(this).parent().find('#previewimg' + z).remove();
$(this).before("<div id='abcd"+ abc +"' class='abcd'><img id='previewimg" + abc + "' src=''/></div>");
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
$(this).hide();
$("#abcd"+ abc).append($("<img/>", {id: 'img', src: 'x.png', alt: 'delete'}).click(function() {
$(this).parent().parent().remove();
}));
}
});
//To preview image
function imageIsLoaded(e) {
$('#previewimg' + abc).attr('src', e.target.result);
};
$('#upload').click(function(e) {
var name = $(":file").val();
if (!name)
{
alert("First Image Must Be Selected");
e.preventDefault();
}
});
});
Tag : JavaScript

|
|
 |
 |
 |
 |
Date :
2018-10-08 16:24:43 |
By :
teedesign |
View :
990 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

PHP MySQL Multiple Upload File to MySQL Database - CreateElement Input File Upload
|
 |
 |
 |
 |
Date :
2018-10-09 09:10:10 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|