The problem is simple. When I take the variable into the array it doesn't work. When I write the variable into inputs it works. How can I pass the variable into the array?
var testW = document.querySelectorAll("input[type='text']");
var testQ = document.getElementsByClassName("deleteObjectbyJS");
var testlength = testW.length;
if(testW[testlength].value == ""){
testQ[0].style.display = "none";
}
Arrays in JS start indexing from 0
to SIZE-1
so your code is wrong here:
if(testW[testlength-1].value == ""){
testQ[0].style.display = "none";
}
I don't know if this solve your problem completly but this is an error for sure
testW[testlength]
应该是testW[testlength-1]
testlength is length of the list. When you trying to access testW[testlength] you actually access non existing element after the last element because elements indexes are between 0 and testlength-1.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.