zoukankan      html  css  js  c++  java
  • <input type="radio" >与<input type="checkbox">值得获取

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@taglib prefix="s" uri="/struts-tags"%>
    <!DOCTYPE html>
    
    
    <html>
    <head>
    
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="styles/03.css">
    <link rel="stylesheet" type="text/css" href="styles/02.css">
    <script type="text/javascript" src="scripts/jquery-1.7.2.min.js"></script>
    
    
    <script>
    	var intervalId;
    	var t ; 
    	var showTime;
    	
    	var startTime = <%=session.getAttribute("startTime")%>
    	var endTime = <%=session.getAttribute("endTime") %>
    	var nowTime = new Date().getTime();
    	var questionType ;
    	var answStr = "";
    	var singleStr = "";
    	var value ;
    	var mes ;
    
    
     	$(function() {
     	
     		questionType = $("#queType").val();
     		if(endTime <= nowTime){
     			alert("考试时间到!系统将自动提交考卷");
    			examFinish();
    			return ;
     		}
     		
     		var seconds = Math.floor((endTime - nowTime)/1000);  
     		t = seconds;
    		intervalId = setInterval("count()", 1000); //定义一个定时器
    		$("#timeCount").html(seconds); //显示当前的秒数		
    	});  
    	
    	function count() {
    		t--; //秒数自减
    		if (t >= 0) {
    			if (t < 10) {
    				$("#timeCount").fadeOut(50, function() {
    				});
    				$("#timeCount").fadeIn(50, function() {
    					$("#timeCount").css("color", "#000");
    				});
    			}
    			if (t < 10) {
    				showTime = "0" + ('' + t);
    			} else {
    				showTime = t;
    			}
    			var mm = parseInt(t / 1000 / 60 % 60, 10);
    			var ss = parseInt(t / 1000 % 60, 10);
    			$("#timeCount").html(showTime); //刷新当前的秒数,重新显示秒数
    			document.cookie = "seconds=" + t;
    			if(showTime <= 0){
    				examFinish();
    				return;
    			}
    		}
    	}
    	
    	/**
    	 * 对get请求处理未post请求
     	*/
    	function post(url, params) {
     	   var temp = document.createElement("form");
     	   temp.action = url;       
     	   temp.method = "post";       
     	   temp.style.display = "none";       
      	   for (var x in params) {       
           	  var opt = document.createElement("textarea");       
              opt.name = x;       
              opt.value = params[x];       
              temp.appendChild(opt);       
           }       
           document.body.appendChild(temp);       
           temp.submit();       
           return temp;
        }
    
    	//获取单选按钮值(包括单选和判断)
    	function getSingleAnswer(id) {
    		var params = document.getElementsByName("singleAnswer" + id);
    		var position;
    		var endPos = 4;
    		id = id + 60 ;
    		var oldMes ; 
    		if(id >= 10){
    			endPos = 4;
    		}
    		for ( var i = 0; i < params.length; i++) {
    			value = params.item(i).getAttribute("value");
    			mes = id + ":"+ value + ";"
    			if(singleStr.indexOf(id + ":") < 0 && params.item(i).checked){
    				singleStr += mes;
    				return ;
    			}else if(singleStr.indexOf(id + ":") >= 0  && params.item(i).checked){
    				position = singleStr.indexOf(id);
    				oldMes = singleStr.substring(position, position + endPos + 1);
    				singleStr = singleStr.replace(oldMes, mes);
    				return ;
    			}
    		}
    	}
    	//获取复选框值,多选题
    	function getMultiAnswer(id) {
    		var box = document.getElementsByName("question.userAnswers"+id);
    		for ( var i = 0; i < box.length; i++) {
    			value = box.item(i).getAttribute("value");
    			mes = id + ":"+ value + ";" ;
    			if(answStr.indexOf(mes) < 0 && box.item(i).checked){
    				answStr += mes;
    				return ;
    			}else if(answStr.indexOf(mes) >= 0  && !box.item(i).checked){
    				answStr = answStr.replace(mes, "");
    				return ;
    			}
    		}
    		//return answStr;
    	}
    
    	
    	function userAnswers(id,type){
    	//alert("type:"+type);
    		if(type == 1){
    			getMultiAnswer(id);
    		}else{
    			getSingleAnswer(id);
    		}
    	}
    	
    	//整个界面提交
    	function examFinish(){
    		var answer = answStr + singleStr;
    		$("#fromBut").attr("action","examAction!examFinish.action?answer="+ answer);
    		$("#fromBut").submit();
    	}
    	
    	
    </script>
    </head>
    
    <body >
    	<div id="overDiv"  style="display:none;">
    		<div class="header">
      		<h1><img src="styles/images/da.png" height="60px" width="60px" text-align="bottom"> 考试结束</h1>
      		<p>
    				<time><%= new java.text.SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss    E").format(new Date()) %></time>
    			</p>
      	</div>
      	<div class="section">
      		<p class="larger">
      			<img src="styles/images/ok.png"  width="40"  height="40"/>  
    			[<span class="red1"><s:property value="#session.user.name"/></span>] 您好,您的考试次数已经够了!
    		</p>
    		<p class="aligncenter">
    			您已考过[ <span class="red1"><s:property value="#session.user.num"/></span> ] 次, 您可以 
    			<a href="index.jsp" class="ala">回首页</a>			
    		</p>
    		</div>
    	
    	</div>
    	<div id="examDiv">
    	
    	
    	<div class="section"  id="ee">
    		<div id="exam">
    		<input type="hidden" name="questionType" id="queType" value="<s:property value="question.type"/>">
    		<form action="" method="post" id = "fromBut">
    			<s:iterator value="questions" status="status" var="list">
    				<s:if test="#list.value[0].type == 2">
    					二、判断题(每题1分)<br/>
    				</s:if>
    				<s:elseif test="#list.value[0].type == 1">
    					一、多选题(每题1分)<br/>
    				</s:elseif>
    				<s:iterator value="#list.value" status="st">
    					<div class="biaot">
    					<s:property value="id"/>、
    					<s:property value="title"/><br/>
    					 </div>
    					<s:if test="type == 2">
    						<input type="radio" name="singleAnswer${id }" value="0"  onclick="userAnswers(${id},${type })" id="userAnswers${id + 60 }" />对
    						<input type="radio" name="singleAnswer${id }" value="1"  onclick="userAnswers(${id},${type })" id="userAnswers${id + 60 }" />错
    						<br/>
    					</s:if>
    					<div class="daan">
    					<s:elseif test="type == 1">
    						<s:iterator value="options" id="option" status="status">
    							<input  type="checkbox" name="question.userAnswers${id}" value="<s:property value="#status.index"/>" onclick="userAnswers(${id},${type })" id="userAnswers${id }">
    								<s:if test="#status.index == 0">A、</s:if>
    								<s:if test="#status.index == 1">B、</s:if>
    								<s:if test="#status.index == 2">C、</s:if>
    								<s:if test="#status.index == 3">D、</s:if>
    								<s:if test="#status.index == 4">E、</s:if>
    								<s:if test="#status.index == 5">F、</s:if>
    								<s:property value="#option"/> 
    							</input>
    							<br>
    						</s:iterator>
    					</s:elseif>
    					</div>
    				</s:iterator>
    				<br/>
    			</s:iterator>
    		
    		</form>	
    			
    		</div>
    	</div>
    	</div>
    	<div class="footer">
    		<%@include file="/foot.jsp" %>
    	</div>
    </body>
    </html>
    

      

  • 相关阅读:
    Markdown语法
    简易银行管理系统
    登录sql sever
    MainActivity中R为红色
    PLC STL any数据类型
    Oracle ORA-12541,ORA-12514错误
    Myeclispe下struts-config.xml文件无法图形界面打开
    SSH报错
    Myeclispe 代码自动补全
    Mac下多个jdk自由切换
  • 原文地址:https://www.cnblogs.com/a757956132/p/4527087.html
Copyright © 2011-2022 走看看