2016-09-08 26 views
-6

所以,我已經寫了很多次這個代碼的副本以前,它工作得很好,但現在它只是不想顯示我的變量!我已經瀏覽了我的工作html代碼中的每一件小事,並將所需的東西複製到我的新文件中,但它只是不想工作... 「str」和「score」應該顯示在左上角的「載入中... 0」,但沒了,沒什麼...... 下面是代碼:爲什麼我的變量不顯示?它一直工作正常

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<meta charset="UTF-8"> 
 
<title>Loading...</title> 
 
\t <style> 
 
\t \t body{ 
 
\t \t \t font-size:20px; 
 
\t \t \t margin:0; 
 
\t \t \t overflow:hidden; 
 
\t \t } 
 
\t \t #str{ 
 
\t \t \t display:block; 
 
\t \t \t font-size:30px; 
 
\t \t \t position: fixed; 
 
\t \t \t top: 1.0em; 
 
\t \t \t left: 1.0em; 
 
\t \t \t user-select: none; 
 
\t \t \t -moz-user-select: none; 
 
\t \t \t -khtml-user-select: none; 
 
\t \t \t -webkit-user-select: none; 
 
\t \t \t -o-user-select: none; 
 
\t \t } 
 
\t \t #str:hover{ 
 
\t \t \t text-decoration: underline; 
 
\t \t \t cursor: pointer; 
 
\t \t } 
 
\t \t #score{ 
 
\t \t \t display:block; 
 
\t \t \t font-size:30px; 
 
\t \t \t position: fixed; 
 
\t \t \t top: 2.0em; 
 
\t \t \t left: 1.0em; 
 
\t \t \t user-select: none; 
 
\t \t \t -moz-user-select: none; 
 
\t \t \t -khtml-user-select: none; 
 
\t \t \t -webkit-user-select: none; 
 
\t \t \t -o-user-select: none; 
 
\t \t } 
 
\t \t #score:hover{ 
 
\t \t \t cursor: default; 
 
\t \t } 
 
\t \t #blackBox{ 
 
\t \t \t background-color:black; 
 
\t \t \t display:block; 
 
\t \t \t position:fixed; 
 
\t \t \t width:0.1%; 
 
\t \t \t bottom:4.0em; 
 
\t \t \t left:0.0em; 
 
\t \t \t padding:0.5em 0em; 
 
\t \t \t text-align:left; 
 
\t \t \t vertical-align:top; 
 
\t \t \t border:2px solid black; 
 
\t \t } 
 
\t \t #blackBox2{ 
 
\t \t \t display:block; 
 
\t \t \t position:fixed; 
 
\t \t \t width:99.5%; 
 
\t \t \t bottom:4.0em; 
 
\t \t \t left:0.0em; 
 
\t \t \t padding:0.5em 0em; 
 
\t \t \t text-align:left; 
 
\t \t \t vertical-align:top; 
 
\t \t \t border:2px solid black; 
 
\t \t } 
 
\t </style> 
 
\t <script type="text/javascript"> 
 

 
\t var _gaq = _gaq || []; 
 
\t _gaq.push(['_setAccount', 'UA-33914917-1']); 
 
\t _gaq.push(['_setDomainName', 'dhmholley.co.uk']); 
 
\t _gaq.push(['_trackPageview']); 
 

 
\t (function() { 
 
\t \t var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
 
\t \t ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
 
\t \t var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
 
\t })(); 
 

 
\t </script> 
 
</head> 
 
<body onload="initialise()"> 
 

 
<div id="blackBox"></div> 
 
<div id="blackBox2"></div> 
 

 
<script> 
 
var prc = 0, 
 
\t W = 1, 
 

 
function initialise(){ 
 
\t createInterface(); 
 
\t updateScore(); 
 
} 
 

 
function mload(){ 
 
    \t prc = prc + 1; 
 
    \t W = prc/100; 
 
    \t document.getElementById("blackBox").style.width = W + "%"; 
 
    \t updateScore(); 
 
} 
 

 
function createInterface(){ 
 
\t var score = document.createElement('div'); 
 
\t score.id = 'score'; 
 
\t score.innerHTML = prc; 
 
\t document.body.appendChild(score); 
 

 
\t var str = document.createElement('div'); 
 
\t str.id = 'str'; 
 
\t str.innerHTML = 'Loading...'; 
 
\t str.onclick = function(){ 
 
\t \t mload(); 
 
\t } 
 
\t document.body.appendChild(str); 
 
} 
 

 
function updateScore(){ 
 
\t document.getElementById('score').innerHTML = prc; 
 
} 
 

 
</script> 
 

 
</body> 
 
</html>

+5

你檢查控制檯它就在那裏你 –

+1

VAR中國= 0,W = 1,函數是一個語法錯誤 –

+1

' 「未捕獲的SyntaxError:意外的標記函數」# – epascarello

回答

0

您可以使用一個var聲明,但聲明多個變量必須用一個關閉每個命令; !它有可能離開,但我wouldnt(也有很好的例子在那裏?

//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