Javascript 首次使用DOM更改Submit表单中未回答问题的颜色
这是我的表格:Javascript 首次使用DOM更改Submit表单中未回答问题的颜色,javascript,dom,getelementbyid,Javascript,Dom,Getelementbyid,这是我的表格: <form id="Test" action="index.php?course=4" method="post" name="Test" onSubmit="IsFormComplete(12)"> 等等。你不需要评估。getElementById使用字符串。试试这个: document.getElementById("Q"+i).style.color = "red"; 就是这些简单的事情让你在凌晨的时候脑子里充满了咖啡因。 function IsFo
<form id="Test" action="index.php?course=4" method="post" name="Test" onSubmit="IsFormComplete(12)">
等等。你不需要评估。getElementById使用字符串。试试这个:
document.getElementById("Q"+i).style.color = "red";
就是这些简单的事情让你在凌晨的时候脑子里充满了咖啡因。
function IsFormComplete(iQuestions) {
var questionNum = iQuestions;
itemOkay=true;
for (var i=1;i<questionNum;i++) {
for (var j=0;j<4;j++) {
var thisItem = eval("document.Test.Q" + i + "[" + j + "].checked");
if (!thisItem) {
itemOkay = false;
document.getElementById(eval("Q" + i)).style.color = "red";
}
}
}
alert("item okay = " + itemOkay);
if (itemOkay) {
return true;
} else {
return false;
}
document.getElementById(eval("Q" + i)).style.color = "red";
document.Test.getElementById(eval("Q" + i)).style.color = "red";
document.getElementById("Q1").style.color = "red"; //To try literal instead of variable
document.getElementById("Q"+i).style.color = "red";