为什么我的HTML,JS测试不起作用?

时间:2014-05-08 19:10:32

标签: javascript html

我们从老师那里得到了这个代码,所以我们可以从中学习。简单来说,这是10个问题测试,每个问题有3个可能的答案。如果你点击了好的答案数量按钮它应该给你回到实际的好答案数量。我不能让这个运行在最新的Chrome,IE等等。每次我点击底部的好答案按钮我得到什么或零。只有实际运行它的浏览器才是PSPad的超老IE。

<html>
<head>
<title>Test HTML</title>


<SCRIPT language=JavaScript>
var contents = true;

function counter(form)   
   {     
    var equal=0;
    if (form.o1[2].status==true)  equal++      
    if (form.o2[0].status==true)  equal++      
    if (form.o3[1].status==true)  equal++      
    if (form.o4[0].status==true)  equal++ 
    if (form.o5[0].status==true)  equal++
    if (form.o6[1].status==true)  equal++
    if (form.o7[0].status==true)  equal++
    if (form.o8[1].status==true)  equal++
    if (form.o9[0].status==true)  equal++
  if (form.o10[2].status==true)  equal++
     {
      form.right.value=" "+equal;
     }
   }
</SCRIPT>



<META http-equiv=Content-Type content="text/html; charset=windows-1250">
</head>
<DIV align=center>
<H3><B>TEST<br>HTML</B></H3>
<HR width="90%" color=#ffff00>
</DIV>
<FORM name=test method=post>
<TABLE width="100%" border=0>
<TBODY>
<TR vAlign=top><TD width="70%">
               <OL>
               <LI>q1</LI></OL>
               <BLOCKQUOTE>
               <br><INPUT type=radio value=A name=o1> Answer0
               <br><INPUT type=radio value=B name=o1> Answer1
               <br><INPUT type=radio value=C name=o1> Answer2
               </BLOCKQUOTE>                        

<TR vAlign=top><TD width="70%">
               <OL>
               <LI value=2>q2</LI></OL>
               <BLOCKQUOTE>
               <br><INPUT type=radio value=A name=o2> Answer0
               <br><INPUT type=radio value=B name=o2> Answer1
               <br><INPUT type=radio value=C name=o2> Answer2
               </BLOCKQUOTE>

<TR vAlign=top><TD width="70%">
               <OL>
               <LI value=3>q3</LI></OL> 
               <BLOCKQUOTE>
               <br><INPUT type=radio value=A name=o3> Answer0
               <br><INPUT type=radio value=B name=o3> Answer1 
               <br><INPUT type=radio value=C name=o3> Answer2
               </BLOCKQUOTE>

<TR vAlign=top><TD width="70%">
               <OL>
               <LI value=4>q4</LI></OL>
               <BLOCKQUOTE>
               <br><INPUT type=radio value=A name=o4> Answer0
               <br><INPUT type=radio value=B name=o4> Answer1
               <br><INPUT type=radio value=C name=o4> Answer2
               </BLOCKQUOTE>

<TR vAlign=top><TD width="70%">
               <OL>
               <LI value=5>q5</LI></OL>
               <BLOCKQUOTE>
               <br><INPUT type=radio value=A name=o5> Answer0
               <br><INPUT type=radio value=A name=o5> Answer1
               <br><INPUT type=radio value=A name=o5> Answer2
               </BLOCKQUOTE>

<TR vAlign=top><TD width="70%">
               <OL>
               <LI value=6>q6</LI></OL>
               <BLOCKQUOTE>
               <br><INPUT type=radio value=A name=o6> Answer0 
               <br><INPUT type=radio value=A name=o6> Answer1    
               <br><INPUT type=radio value=A name=o6> Answer2
               </BLOCKQUOTE>

<TR vAlign=top><TD width="70%">
               <OL>
               <LI value=7>q7</LI></OL>
               <BLOCKQUOTE>
               <br><INPUT type=radio value=A name=o7> Answer0
               <br><INPUT type=radio value=A name=o7> Answer1   
               <br><INPUT type=radio value=A name=o7> Answer2
               </BLOCKQUOTE>

<TR vAlign=top><TD width="70%">
               <OL>
               <LI value=8>q8</LI></OL>
               <BLOCKQUOTE>
               <br><INPUT type=radio value=A name=o8> Answer0
               <br><INPUT type=radio value=A name=o8> Answer1    
               <br><INPUT type=radio value=A name=o8> Answer2
               </BLOCKQUOTE>

<TR vAlign=top><TD width="70%">
               <OL>
               <LI value=9>q9</LI></OL>
               <BLOCKQUOTE>
               <br><INPUT type=radio value=A name=o9> Answer0
               <br><INPUT type=radio value=A name=o9> Answer1  
               <br><INPUT type=radio value=A name=o9> Answer2
               </BLOCKQUOTE>

<TR vAlign=top><TD width="70%">
               <OL>
               <LI value=10>q10</LI></OL>
               <BLOCKQUOTE>
               <br><INPUT type=radio value=A name=o10> Answer0
               <br><INPUT type=radio value=A name=o10> Answer1 
               <br><INPUT type=radio value=A name=o10> Answer2
               </BLOCKQUOTE>
</TBODY>
</TABLE>
<HR width="90%" color=#ffff00>
<P align=center>
<INPUT style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma" onclick="return counter(this.form)" type=button value="Number of good answers"> 
<INPUT size=5 name=right> 
</FORM>
</BODY>
</HTML>

感谢您解决我的问题。我在JS中并不是那么好。

编辑:谢谢你们,你们真的是最棒的。 :)

4 个答案:

答案 0 :(得分:2)

脚本正在检查输入的status属性。此属性仅在旧版Internet Explorer中受支持。

答案 1 :(得分:1)

在您的教师代码中,status==true看起来不再受支持并返回未定义的值。您应该将Javascript函数更改为以下内容:

function counter(form){     
    var equal=0;
    if (form.o1[2].checked==true){equal++;}
    if (form.o2[0].checked==true){equal++;}
    if (form.o3[1].checked==true){equal++;}
    if (form.o4[0].checked==true){equal++;}
    if (form.o5[0].checked==true){equal++;}
    if (form.o6[1].checked==true){equal++;}
    if (form.o7[0].checked==true){equal++;}
    if (form.o8[1].checked==true){equal++;}
    if (form.o9[0].checked==true){equal++;}
  if (form.o10[2].checked==true){
    equal++;
    form.right.value=" "+equal;
    }
}

.checked将返回您正在寻找的布尔状态。此外,您的教师代码格式为TERRIBLY。我甚至不确定只是在没有正确格式化的情况下更改为.checked就行了。

答案 2 :(得分:0)

你没有使用正确格式的HTML格式...我为你提出了一个问题,请关注它并更改其他答案属性

<html>
<head>
<title>Test HTML</title>


<SCRIPT >
var contents = true;

function counter(form)   
{     
var equal=0;
if (form.o1[2].status==true)  equal++      
if (form.o2[0].status==true)  equal++      
if (form.o3[1].status==true)  equal++      
if (form.o4[0].status==true)  equal++ 
if (form.o5[0].status==true)  equal++
if (form.o6[1].status==true)  equal++
if (form.o7[0].status==true)  equal++
if (form.o8[1].status==true)  equal++
if (form.o9[0].status==true)  equal++
if (form.o10[2].status==true)  equal++
 {
  form.right.value=" "+equal;
 }
}
</SCRIPT>




</head>
<body>
<DIV align="center">
<H3><B>TEST<br>HTML</B></H3>
<HR width="90%" color=#ffff00>
</DIV>
<FORM name="test" method="post">
<TABLE width="100%" border=0>
<TBODY>
<TR vAlign="top"><TD width="70%">
           <OL>
           <LI>q1</LI></OL>
           <BLOCKQUOTE>
           <br><INPUT type="radio" value="A" name="o1"> Answer0

           </BLOCKQUOTE>                        

<TR ><TD width="70%">
           <OL>
           <LI value=2>q2</LI></OL>
           <BLOCKQUOTE>

           </BLOCKQUOTE>

<TR ><TD width="70%">
           <OL>
           <LI value=3>q3</LI></OL> 
           <BLOCKQUOTE>

           </BLOCKQUOTE>


 </TBODY>
 </TABLE>
 <HR width="90%" color=#ffff00>
  <P align=center>
 <INPUT style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma" onclick="return counter(this)"     type=button value="Number of good answers"> 
 <INPUT size=5 name=right> 
</FORM>
 </BODY>
 </HTML>

使用适当的“”,在哪里......

答案 3 :(得分:0)

您的代码中有许多错误: 1.要检查的状态 2.代码在许多适当的位置不包含分号(;)。 3. HTML中的标签是通用的而不是自定义的。因此,请使用标准HTML标记。

整个代码应该是: -

<html>
<head>
 <META http-equiv=Content-Type content="text/html; charset=windows-1250">   
<title>Test hTML</title>


<script language=JavaScript type="text/javaScript">
var contents = true;

function counter(form)   
   {  
    var equal=0;
    if (form.o1[2].checked==true)  equal++;      
    if (form.o2[0].checked==true)  equal++;     
    if (form.o3[1].checked==true)  equal++;     
    if (form.o4[0].checked==true)  equal++;
    if (form.o5[0].checked==true)  equal++;
    if (form.o6[1].checked==true)  equal++;
    if (form.o7[0].checked==true)  equal++;
    if (form.o8[1].checked==true)  equal++;
    if (form.o9[0].checked==true)  equal++;
    if (form.o10[2].checked==true) equal++;
      alert(form.right.value=" "+equal);
      form.right.value=" "+equal;
   }
</script>




</head>
<body>
<div align=center>
<h3><B>TEST<br>HTML</B></h3>
<HR width="90%" color=#ffff00>
</div>
<form name=test method=post>
<table width="100%" border=0>
<tbbody>
<tr vAlign=top><td width="70%">
               <OL>
               <LI>q1</LI></OL>
               <BLOCKQUOTE>
               <br><input type=radio value=A name=o1> Answer0
               <br><input type=radio value=B name=o1> Answer1
               <br><input type=radio value=C name=o1> Answer2
               </BLOCKQUOTE>                        

<tr vAlign=top><td width="70%">
               <OL>
               <LI value=2>q2</LI></OL>
               <BLOCKQUOTE>
               <br><input type=radio value=A name=o2> Answer0
               <br><input type=radio value=B name=o2> Answer1
               <br><input type=radio value=C name=o2> Answer2
               </BLOCKQUOTE>

<tr vAlign=top><td width="70%">
               <OL>
               <LI value=3>q3</LI></OL> 
               <BLOCKQUOTE>
               <br><input type=radio value=A name=o3> Answer0
               <br><input type=radio value=B name=o3> Answer1 
               <br><input type=radio value=C name=o3> Answer2
               </BLOCKQUOTE>

<tr vAlign=top><td width="70%">
               <OL>
               <LI value=4>q4</LI></OL>
               <BLOCKQUOTE>
               <br><input type=radio value=A name=o4> Answer0
               <br><input type=radio value=B name=o4> Answer1
               <br><input type=radio value=C name=o4> Answer2
               </BLOCKQUOTE>

<tr vAlign=top><td width="70%">
               <OL>
               <LI value=5>q5</LI></OL>
               <BLOCKQUOTE>
               <br><input type=radio value=A name=o5> Answer0
               <br><input type=radio value=A name=o5> Answer1
               <br><input type=radio value=A name=o5> Answer2
               </BLOCKQUOTE>

<tr vAlign=top><td width="70%">
               <OL>
               <LI value=6>q6</LI></OL>
               <BLOCKQUOTE>
               <br><input type=radio value=A name=o6> Answer0 
               <br><input type=radio value=A name=o6> Answer1    
               <br><input type=radio value=A name=o6> Answer2
               </BLOCKQUOTE>

<tr vAlign=top><td width="70%">
               <OL>
               <LI value=7>q7</LI></OL>
               <BLOCKQUOTE>
               <br><input type=radio value=A name=o7> Answer0
               <br><input type=radio value=A name=o7> Answer1   
               <br><input type=radio value=A name=o7> Answer2
               </BLOCKQUOTE>

<tr vAlign=top><td width="70%">
               <OL>
               <LI value=8>q8</LI></OL>
               <BLOCKQUOTE>
               <br><input type=radio value=A name=o8> Answer0
               <br><input type=radio value=A name=o8> Answer1    
               <br><input type=radio value=A name=o8> Answer2
               </BLOCKQUOTE>

<tr vAlign=top><td width="70%">
               <OL>
               <LI value=9>q9</LI></OL>
               <BLOCKQUOTE>
               <br><input type=radio value=A name=o9> Answer0
               <br><input type=radio value=A name=o9> Answer1  
               <br><input type=radio value=A name=o9> Answer2
               </BLOCKQUOTE>

<tr vAlign=top><td width="70%">
               <OL>
               <LI value=10>q10</LI></OL>
               <BLOCKQUOTE>
               <br><input type=radio value=A name=o10> Answer0
               <br><input type=radio value=A name=o10> Answer1 
               <br><input type=radio value=A name=o10> Answer2
               </BLOCKQUOTE>
</tbody>
</table>
<HR width="90%" color=#ffff00>
<p align=center>
<input style="font-size:8pt; font-family:Tahoma" onclick="return counter(this.form);" type=button value="Number of good answers"> 
<input  value="" name=right> 
</form>
</body>
</html>