好吧,我有一些 id='0','1','2','3' 等的复选框。所以我需要获取复选框的文本。这是PHP中复选框的代码。
'<input id="'.$i.'"type="checkbox" name="option1" value="a1" onclick="checkYears()">'.$years[$i].'</input>
所以我需要得到 $years[$i]-value。我正在使用这段代码。
while (bool==false)
{
if (document.getElementById(i)!=null)
{
if (document.getElementById(i).checked)
{
years.push(1);
yearsValue.push(document.getElementById(i).innerHTML);
document.getElementById(i).innerText="WORKS";
console.log(yearsValue[i]);
}
else
{
years.push(0);
yearsValue.push(document.getElementById(i)).innerHTML);
console.log(yearsValue[i]);
}
}
else
{
bool=true;
}
i++;
}
添加 0 和 1 可以,但是当我尝试使用 innerHTML 时,控制台中有未定义的值。
有什么建议么?