Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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代码吗?_Javascript - Fatal编程技术网

有人能解释一下Javascript代码吗?

有人能解释一下Javascript代码吗?,javascript,Javascript,我正在学校做一个项目,作为其中的一部分,我必须在html表单中包含单选按钮。下面是一些我不太理解的Javascript代码。代码运行良好。有人能给我解释一下代码是如何工作的吗 var check = false; for (var i=0; i < document.ExamEntry.Level.length; i++) { if (document.ExamEntry.Level[i].checked) { var radiovalue = doc

我正在学校做一个项目,作为其中的一部分,我必须在html表单中包含单选按钮。下面是一些我不太理解的Javascript代码。代码运行良好。有人能给我解释一下代码是如何工作的吗

var check = false; 
for (var i=0; i < document.ExamEntry.Level.length; i++)
   {
   if (document.ExamEntry.Level[i].checked)
      {
      var radiovalue = document.ExamEntry.Level[i].value;
      check =true; 
      var usermessage=confirm("You have chosen: ".concat(radiovalue));

          if(usermessage == false)
              {
                 var radiovalue = "";
                check = false;
              }
      }
   }
<!--I understand the code below, its just some parts of the above code.
if (check ==false)
       {
       msg+="ERROR:You must select an entry level \n";  
       document.getElementById ('Levelcell'). style.color = "red";
       result = false;
       }
var检查=false;
for(var i=0;i所有表单元素都绑定到全局HTML文档变量。因此,页面上的某个地方必须有一个名为“
ExamEntry
”的表单:

<form name='ExamEntry' id='ExamEntry` ...

我添加了一些注释来帮助解释这一点:

var check = false; 

// set a variable 'i' from 0 up to the ExamEntry level length (so for each radio)
// if there are 10 items, this code will run 10 times, each time with 'i' a different value from 0 to 9
for (var i=0; i < document.ExamEntry.Level.length; i++)
   {

   // is the radio button checked? If so, do the stuff inside. If not, skip this part
   if (document.ExamEntry.Level[i].checked)
      {

      // set variable radiovalue to the value of the particular radio button
      var radiovalue = document.ExamEntry.Level[i].value;

      // set the check variable to true
      check =true; 

      // ask the user to confirm the value and set usermessage based on confirmation
      var usermessage=confirm("You have chosen: ".concat(radiovalue));

        // if the user hits no on confirm, it will reset the radiomessage to blank and check to false
        if(usermessage == false)
          {
             var radiovalue = "";
             check = false;
          }
      }
   }
var检查=false;
//将变量“i”设置为从0到考试级别长度(每个收音机都是如此)
//如果有10个项目,此代码将运行10次,每次使用0到9之间的不同值“i”
for(var i=0;i
这是我不理解的主要部分:for(var I=0;Idocument
是一个引用DOM的全局html变量。因此,页面上的所有内容都是文档的一部分。html页面上必须有一个名为
ExamEntry
的表单,因为所有表单都绑定到文档全局变量。
Level
然后必须是一个输入变量在该表单上。对于每个输入,它都会迭代并查找所选的单选按钮。如果找到,它会告诉您。否则,它会告诉您有错误消息。感谢您对回答我的问题感兴趣!!您的问题非常广泛。您能准确指出您不理解的内容吗?您知道
f吗或者
如果
做什么?JavaScript中的
文档
是什么?哪一行给您带来了麻烦?i++,级别[i]。选中,级别[i].value感谢您的分步代码分析。我不清楚Ivar check = false; // set a variable 'i' from 0 up to the ExamEntry level length (so for each radio) // if there are 10 items, this code will run 10 times, each time with 'i' a different value from 0 to 9 for (var i=0; i < document.ExamEntry.Level.length; i++) { // is the radio button checked? If so, do the stuff inside. If not, skip this part if (document.ExamEntry.Level[i].checked) { // set variable radiovalue to the value of the particular radio button var radiovalue = document.ExamEntry.Level[i].value; // set the check variable to true check =true; // ask the user to confirm the value and set usermessage based on confirmation var usermessage=confirm("You have chosen: ".concat(radiovalue)); // if the user hits no on confirm, it will reset the radiomessage to blank and check to false if(usermessage == false) { var radiovalue = ""; check = false; } } }