我正在尝试处理表格。目前,该按钮已禁用。但是,当您单击复选框时,该按钮应启用,如果您没有单击复选框,则应再次禁用该按钮。当我单击复选框时,我无法启用按钮。我的循环可能有问题。循环在函数 checkAge 中。有什么解决办法吗?
Javascript
function checkAge(e){
var theTarget = e.target ? e.target : e.srcElement;
alert(theTarget.id);
var form = document.getElementById("form");
if (document.getElementById("content")) {
form.removeChild(document.getElementById("content"));
}
if(theTarget.id == "fourteen"){
var newDiv = document.createElement("div");
newDiv.setAttribute("id", "content");
var br = document.createElement("br");
newDiv.appendChild(br);
var br = document.createElement("br");
newDiv.appendChild(br);
newDiv.appendChild(document.createTextNode("Vilka seriefigurer träffade du?"));
var br = document.createElement("br");
newDiv.appendChild(br);
var musse = document.createElement('input');
musse.setAttribute("type", "checkbox");
musse.setAttribute("name", "musse");
musse.setAttribute("value", "musse");
musse.setAttribute("id", "musse");
newDiv.appendChild(musse);
newDiv.appendChild(document.createTextNode("Musse"));
var br = document.createElement("br");
newDiv.appendChild(br);
var adi = document.createElement('input');
adi.setAttribute("type", "checkbox");
adi.setAttribute("name", "adi");
adi.setAttribute("value", "adi");
adi.setAttribute("id", "adi");
newDiv.appendChild(adi);
newDiv.appendChild(document.createTextNode("Ådi"));
var br = document.createElement("br");
newDiv.appendChild(br);
var bamse = document.createElement('input');
bamse.setAttribute("type", "checkbox");
bamse.setAttribute("name", "bamse");
bamse.setAttribute("value", "bamse");
bamse.setAttribute("id", "bamse");
newDiv.appendChild(bamse);
newDiv.appendChild(document.createTextNode("Bamse"));
var br = document.createElement("br");
newDiv.appendChild(br);
var input = document.createElement("input");
input.setAttribute("type", "submit");
input.setAttribute("name", "submit");
input.setAttribute("id", "submit");
input.setAttribute("value", "Skicka");
newDiv.appendChild(input);
form.appendChild(newDiv);
var inputs = document.getElementsByTagName("input");
for(i=0; i<inputs.length; i++){
input.disabled = true;
if(inputs[i].type == "checkbox" && inputs[i].checked){
input.disabled = false;
}
else{
input.disabled = true;
}
}
}