There are so many things that I can't understand in JavaScript, some problems I know how to modify, but I can't explain why. Recently, another one has been encountered.
A "Select All-delete" feature, the following is the following is the click "Delete" button out of the trigger code fragment: var tbody = document.getElementById ("MAPPINGTD");
var Mappingcheck = document.getelementsbyname ("checkboxinmapping");
var length = Mappingcheck.length;
for (i = 0; < length; ) {
if (Mappingcheck.item (i). Checked) {
var str_value = Mappingcheck.item (i). value;
var tr = document.getElementById (str_value);
Tbody.removechild (TR);
}
else {
i++;
}
}
This code sometimes "select all" and can not delete all the selected information, the probability is about 2/3. My first reaction was to change the for to while, and in the past encountered similar problems, for and while in JS sometimes not interchangeable. The following is the modified code: var tbody = document.getElementById ("MAPPINGTD");
var Mappingcheck = document.getelementsbyname ("checkboxinmapping");
var length = Mappingcheck.length;
var i = 0;
while (I < length) {
if (Mappingcheck.item (i). Checked) {
var str_value = Mappingcheck.item (i). value;
var tr = document.getElementById (str_value);
Tbody.removechild (TR);
}
else {
i++;
}
}
This time can complete the required functions, two pieces of code should be interchangeable, do not know why this problem, I know it, I do not know why.