![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 544 Pomógł: 5 Dołączył: 18.08.2009 Ostrzeżenie: (0%) ![]() ![]() |
Mam problem ze zdarzeniem i odczytywaniem danych z input[type="file"]. Chcę zrobić tak że po wybraniu pliku, div .upload-button zmienia kolor. Mam taki kod:
Kod var count = document.getElementsByClassName("upload").length; var i=0; for (i; i<count; i++) { document.getElementsByClassName("upload")[i].addEventListener("change", check_upload(i)); } function check_upload(i) { if (document.getElementsByClassName("upload")[i].value!='') { document.getElementsByClassName("upload-button")[i].style.background="green"; console.log("You have selected file to upload"); } else { document.getElementsByClassName("upload-button")[i].style.background="red"; console.log("No file choosen"); } } Kod <div class="upload-button"></div>
<input type="file" name="file" class="upload"> |
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Moderatorzy Postów: 36 559 Pomógł: 6315 Dołączył: 27.12.2004 ![]() |
No bo ty w ogole tego i nie potrzebujesz...
Przeciez masz tam this ktore jest twoim elementem wiec: Kod for (i; i<count; i++) {
document.getElementsByClassName("upload")[i].addEventListener("change", function() {check_upload(this)}); } function check_upload(obj) { //i potem nie //document.getElementsByClassName("upload")[i] //a //obj //itd
Powód edycji: [nospor]:
|
|
|
![]() ![]() |
![]() |
Aktualny czas: 15.10.2025 - 12:30 |