如何将表链接在一起

时间:2016-04-26 01:45:45

标签: javascript html

我是HTML& amp;的新手JS我想把我的两张桌子连在一起。就像当计时器达到0时,分数将自动更新,问题将以新的开始,问题不会再次重复。

<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta http-equiv="refresh" content="6">  
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script>
function shuffleArray(array) {
		for (var i = array.length - 1; i > 0; i--) {
			var j = Math.floor(Math.random() * (i + 1));
			var temp = array[i];
			array[i] = array[j];
			array[j] = temp;
		}
		return array;	
	}

console.log ('DEBUG shuffleArray()')

</script>

<style type="text/css">
    table, 
    td.col2 {width:70%}
    td.col1 {width:30%}
	table, th , td{
		border: 1px solid black;
		border-collapse: collapse;
	}
	th, td {
		padding: 150px;
	}
	
</style>
</HEAD>
<body onload="setTimeout('nextPic()',2000)">
	
	<table align="center" >
		<tr>
			<td class="col1">
			
			<script type="text/JavaScript">
			<!--
			var picCount=0; // global
			var picArray= ["image/5.png","image/4.png","image/3.png","image/2.png","image/1.png"]
			//
			// gets next picture in array
				function nextPic()
						{ // check if adding 1 exceeds number of pics in array
						picCount=(picCount+1<picArray.length)? picCount+1 : 0;
						// build the img to write to page using the new pic reference
						var build='<img border="0" src="'+picArray[picCount]+'" width="205" height="100">\
						';
				document.getElementById("imgHolder").innerHTML=build;
				// repeat this after a puse of 2000ms (2sec).
				setTimeout('nextPic()',1000)
				}
				//-->
			</script>
				
		
			<div id="imgHolder">
				<img border="0" src="image/5.png" width="205" height="100">
			</div>
		
			</td>
			<td class="col2" id="demo" align="left" >
			
			<script>
				var point = 25;
				var pos = 0, test, test_status, question, choice, choices, chA, chB, chC, chD, correct = 0;
				var questions = [
					[ "Which of the following is not a rule of thumb for password?", 
								"Follow the strong password references ", 
								"Use personal reference like birthday,name and home address",
								"Don&#39;t disclose any of your password to anyone ",				
								"Do not use any words found in the dictionary", 
								"B" ],
					[ "Which is not a  way to prevent you from being social engineered? ", 
								"Be wary of emails, instant messages and phone calls", 
								"Pay attention to website URL", 
								"Give personal inforamtion to others",
								"Never download email attachment from unknown senders",
								"C" ],
					[ "What makes a good password?", 
								"At least 8 characters", 
								"Contain Numbers and Symbols", 
								"Contain both upper and lower case", 
								"All the above",  
								"D" ],
					[ "What should you do if you receive an email attachment from someone you don&#39;t know?", 
								"Do not open the attachment.", 
								"Open the attachment if the subject line seems appropriate.", 
								"Reply to the email and request more information.",
								"Open the attachment if your virus software doesn't alert you not to.",
								"A" ],
					["Which one of these ways is not a way to prevent spams from email?", 
								"Prevention",
								"Use Firewall", 
								"Use Filters",
								"Report Spammers",
								"B"],
						["Which of the following is not a rule of thumb for password?", 
								"Follow the strong password references ", 
								"Use personal reference like birthday,name and home address",
								"Don&#39;t disclose any of your password to anyone ",				
								"Do not use any words found in the dictionary", 
								"B"],
					["Are all the ways to prevent identity theft?", 
								"Strengthen Password", 
								"Don&#39;t give out personal information if it is necessary",
								"Shred all your letter before throwing it again",
								"All the above", 
								"D"],
					["Are all these the don&#39;ts of the IT security?", 
								"Don&#39;t be trick in giving sensitive data away", 
								"Don&#39;t leave sensitive info lying around",
								"Be cautious of all suspicious email and websites",				
								"All the above", 
								"D"],
					["What are the ways to protect you on social media?", 
								"Use a strong password", 
								"Be cautious on social media like email or social media message",
								"Know what you are sharing",				
								"All the above", 
								"D"],
					["Which of these are not the pre-cautions when you use the free Wi-Fi at public places like cafe and airports?", 
								"Enable firewall", 
								"Turn on Sharing",
								"Turn off Wi-Fi when not using",				
								"Use HTTPS and SSL whenever is possible ", 
								"B"] 
				];
				function _(x){
					return document.getElementById(x);
				}
				function renderQuestion(){
					test = _("test");
					if(pos >= questions.length){
						
						_("test_status").innerHTML = "Test Completed";
						pos = 0;
						ScorePlus = 0;
						ScoreMinus = 0;
						return false;
					}
					
					question = questions[pos][0];
					chA = questions[pos][1];
					chB = questions[pos][2];
					chC = questions[pos][3];
					chD = questions[pos][4];
					
					test.innerHTML = "<h3>"+question+"</h3>";
					test.innerHTML += "<input type='radio' name='choices' value='A'> "+chA+"<br>";
					test.innerHTML += "<input type='radio' name='choices' value='B'> "+chB+"<br>";
					test.innerHTML += "<input type='radio' name='choices' value='C'> "+chC+"<br>";
					test.innerHTML += "<input type='radio' name='choices' value='D'> "+chD+"<br><br>";
					test.innerHTML += "<button onclick='checkAnswer()'>Submit Answer</button>";
				}
				function checkAnswer(){
					choices = document.getElementsByName("choices");
					for(var i=0; i<choices.length; i++){
						if(choices[i].checked){
							choice = choices[i].value;
						}
					}
					if(choice == questions[pos][5]){
						ScorePlus++;	
						//point++;	
											
					}
					else if(choice != questions[pos][5]){
						ScoreMinus--;
						//point--;
					}
					pos++;
					renderQuestion();
				
				}
				window.addEventListener("load", renderQuestion, false);


					
					
					shuffleArray (questions);	//Shuffle the whole allQuestions array	
						

					
			</script>
					<h2 id="test_status"></h2>
					<div id="test"></div>
			</td>
		</tr>
	</table>


</BODY>
</HTML>

1 个答案:

答案 0 :(得分:0)

您无法使用HTML刷新。

//Vars
var http       = require('http');
var express    = require("express");
var app        = express();
var path       = require("path");
var connect    = require("connect");
var io = require('socket.io').listen(server);
var socket     = io.listen(server);

//Defined port

const PORT = 8080;

//Connection handler

function handleRequest(request, response){  
response.end(request.url);
};

var server = http.createServer(handleRequest);

//Log all connections made


//Show .html file

app.get('/',function(req,res){  
res.sendFile(path.join(__dirname+'/index.html'));
});

//Port to listen to

app.listen(8080);

每6秒页面重新加载一次,一切都重新开始。 您必须以更换图像的方式执行此操作,而不是刷新。