为什么我的变量不显示?我一直工作得很好

Why won't my variables display? It've always worked fine

本文关键字:一直 工作 很好 我的 变量 显示 为什么      更新时间:2023-09-26

所以,我已经写了很多次这段代码的副本之前,它已经工作得很好,但现在它只是不想显示我的变量!我已经查看了工作中的html代码中的每一件小事,并将所需的内容复制到我的新文件中,但它就是不想工作……"str"answers"score"应该显示为"Loading…"左上角是0",但是没有,什么都没有…下面是代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Loading...</title>
	<style>
		body{
			font-size:20px;
			margin:0;
			overflow:hidden;
		}
		#str{
			display:block;
			font-size:30px;
			position: fixed;
			top: 1.0em;
			left: 1.0em;
			user-select: none;
			-moz-user-select: none;
			-khtml-user-select: none;
			-webkit-user-select: none;
			-o-user-select: none;
		}
		#str:hover{
			text-decoration: underline;
			cursor: pointer;
		}
		#score{
			display:block;
			font-size:30px;
			position: fixed;
			top: 2.0em;
			left: 1.0em;
			user-select: none;
			-moz-user-select: none;
			-khtml-user-select: none;
			-webkit-user-select: none;
			-o-user-select: none;
		}
		#score:hover{
			cursor: default;
		}
		#blackBox{
			background-color:black;
			display:block;
			position:fixed;
			width:0.1%;
			bottom:4.0em;
			left:0.0em;
			padding:0.5em 0em;
			text-align:left;
			vertical-align:top;
			border:2px solid black;
		}
		#blackBox2{
			display:block;
			position:fixed;
			width:99.5%;
			bottom:4.0em;
			left:0.0em;
			padding:0.5em 0em;
			text-align:left;
			vertical-align:top;
			border:2px solid black;
		}
	</style>
	<script type="text/javascript">
	  var _gaq = _gaq || [];
	  _gaq.push(['_setAccount', 'UA-33914917-1']);
	  _gaq.push(['_setDomainName', 'dhmholley.co.uk']);
	  _gaq.push(['_trackPageview']);
	  (function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	  })();
	</script>
</head>
<body onload="initialise()">
<div id="blackBox"></div>
<div id="blackBox2"></div>
<script>
var prc = 0,
	W = 1,
function initialise(){
	createInterface();
	updateScore();
}
function mload(){
  	prc = prc + 1;
  	W = prc / 100;
  	document.getElementById("blackBox").style.width = W + "%";
  	updateScore();
}
function createInterface(){
	var score = document.createElement('div');
	score.id = 'score';
	score.innerHTML = prc;
	document.body.appendChild(score);
	var str = document.createElement('div');
	str.id = 'str';
	str.innerHTML = 'Loading...';
	str.onclick = function(){
		mload();
	}
	document.body.appendChild(str);
}
function updateScore(){
	document.getElementById('score').innerHTML = prc;
}
</script>
</body>
</html>

你可以用一个var语句声明多个变量,但是你必须用一个;! 有可能离开它,但我不会(有很好的例子:

//not good but should work:
var a,b
function c(){}
//the best solution:
var a,b;
function c(){};
//what you did
var a,b,function c(){};
//wich is invalid