问题描述
- 单选试题 答案保存 调用另一个function
-
当点击下一题跳转页面,第五次时没有变为提交,且无法触发score方法,同时没选一题答案,跳转页面时如何存储<SCRIPT LANGUAGE="JavaScript"> function Engine(question, answer) { yourAns[question]=answer; } <!-- Begin function Score(){ var answerText = "看看你的成绩如何?n------------------------------------n"; for(i=1;i<=5;i++){ ans[i]=s; answerText=answerText+"n问题:"+i+"n"; if(ans[i]!=yourAns[i]){ answerText=answerText+"n正确的答案是: "+ans[i]+"n"; } else{ answerText=answerText+" n对的 n"; score++; } } answerText=answerText+"nn你的成绩是 : "+score+"n"; //now score the user alert(answerText); } // End --> </script> <script> var index=1; function f1(obj){ if(obj.value=="下一题"){ window.location.href="1.asp"; } } function f2(obj){ if(obj.value=="下一题"){ window.location.href="1.asp"; } } function f3(obj){ if(obj.value=="下一题"){ window.location.href="1.asp"; } } function f4(obj) { if (document.form1.obj.value=="下一题") { document.form1.obj.value="提交"; } window.location.href="1.asp"; } function f5(){ if(document.form1.obj.value=="提交"){ obj.onclick=score(); } } function test(obj){ if (index>5){//防止超出 index=1; } eval('f'+index+'();'); index++; } </script> <body> <form id="form1" name="form1" method="post" action=""> <p> <label> <input type="radio" name="RadioGroup1" value="1" id="RadioGroup1_0" onClick="Engine(2, this.value)"/> p1</label> <label> <input type="radio" name="RadioGroup1" value="2" id="RadioGroup1_1" onClick="Engine(2, this.value)"/> p2</label> </p> </form> <form name="form1" method="post" action=""> <input name="obj" type="submit" id="obj" value="下一题" onClick="test(this);"> </form> </body>
解决方案
你明明提交的是asp,应该在第四次的时候asp输出的时候,改掉obj的value,用js改的结果就是经过asp后被刷掉了
解决方案二:
eval('f'+index+'();')这句执行f1,f2,f3时报错了,if(obj.value=="下一题"){中的obj是null
时间: 2024-10-27 10:25:14