I have the following HTML
-
A radiobutton have no innerhtml. You need to target the label. If it's always directly after the radio-button, try something like radios[i].nextSibling.innerhtml
.
讨论(0)
-
You have to access the corresponding label separately, since it resides in a separate tag. Because the labels' for
attribute is equal to its option's id
, you can get to the label easily:
for(var i=0; i<radios.length; i++) {
var selector = 'label[for=' + radios[i].id + ']';
var label = document.querySelector(selector);
var text = label.innerHTML;
// do stuff
}
Also check out this fiddle
讨论(0)