문제를 일으키는 코드가 있습니다 ....
"use strict";
$(document).ready(function() {
$(".mylbl").click(function() {
var imageslen, imagesSize, imagesName; //decleartion variale
//Intiallize variables for prevent to upload many time images
imageslen = imagesSize = imagesName = 0;
$(".inputfile").click();
$(".inputfile").change(function() {
imageslen = 0;
var uploadedImages = $(".inputfile")[0].files;
imageslen = uploadedImages.length;
imagesSize = [];
imagesName = [];
for (var i = 0; i < imageslen; i++) {
imagesSize[i] = uploadedImages[i].size;
imagesName[i] = uploadedImages[i].name;
console.log(imagesSize[i]);
console.log(imagesName[i]);
}
});
});
});
body {
margin: 0px;
padding: 0px;
background-color: #ccc;
color: #f4f9c4;
width: 100%;
height: 100%;
}
form {
box-sizing: border-box;
border: 10px solid #fff;
width: 250px;
height: 300px;
margin: auto;
padding: 20px;
}
.mylbl {
box-sizing: border-box;
text-align: center;
display: block;
min-width: 80px;
height: 50px;
background-color: #ff4500;
line-height: 300%;
border: 5px solid #C33100;
border-radius: 10px;
cursor: pointer;
}
.inputfile {
display: none;
}
.btn {
width: 200px;
height: 70px;
background-color: #129EA4;
border: none;
border: 5px solid #fff;
border-radius: 10px;
margin: 10px 10px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form class="myform" method="post" id="myform" enctype="multipart/form-data">
<input type="file" name="album" name="gallry[]" multiple class="inputfile" />
<label for="imgrs" class="mylbl">Please Choose Images..</label>
<input id="_d11re" type="button" name="addimagedata" value="Upload" class="_p25ed btn" />
</form>
문제는 변수 imageslen이 재설정되지 않는 js 코드에 있습니다. 처음 이미지를 업로드 할 때 코드가 올바르게 작동하고 이미지 업로드 이미지 업로드를 위해 두 번째로 해당 labal ( "please choose image")을 클릭하면 두 번. . 여기에 Google 크롬의 작은 이미지가 표시됩니다.
mylbl
클릭 할 때마다 새 Change EventListener가에 바인딩됩니다 inputfile
.
$(".mylbl").click(function() {
$(".inputfile").click();
// move the rest of the function from HERE
}
// to HERE
더 많은 문제가 있으면 jsFiddle 또는 다른 것을 만들어 중간 결과를 보여주십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다