【发布时间】:2017-01-16 17:07:15
【问题描述】:
所以,我之前已经多次编写了这段代码的副本,它工作得很好,但现在它只是不想显示我的变量!我已经查看了我工作的 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>
【问题讨论】:
-
你检查控制台了吗?它就在你身边
-
var prc=0,w=1,function 是语法错误
-
"Uncaught SyntaxError: Unexpected token function" -
@Jonasw Omg,谢谢兄弟!我不敢相信那是事情。困扰我的事情是我的工作代码是这样写的,没有问题......奇怪
-
添加为答案
标签: javascript html css styles