Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 首次使用DOM更改Submit表单中未回答问题的颜色_Javascript_Dom_Getelementbyid - Fatal编程技术网

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";