为什么我的变量不显示?它一直很好

时间:2016-09-08 16:54:25

标签: javascript html css styles

所以,我之前已经多次写过这段代码的副本而且它工作得很好但是现在它只是不想显示我的变量!我查看了我的工作html代码中的每一件小事,并将所需的东西复制到我的新文件中,但它只是不想工作...... “str”和“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>

1 个答案:

答案 0 :(得分:0)

您可以使用一个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