0
所以这里是我的代码,用于我目前为止的扩展。我想制作一个游戏,当它出现时点击该点。问题是无论我做什么,我点击按钮似乎都会出错。为什么它给我一个错误onclick?
popup.js
//The Dot
(function makeDiv(){
// vary size for fun
var divsize = ((Math.random()*100) + 20).toFixed();
var color = '#'+ Math.round(0xffffff * Math.random()).toString(16);
$newdiv = $('<button type="button" id="button" style=" border-radius: 500px;outline: none;padding: 0;border: none;"></button>').css({
'width':divsize+'px',
'height':divsize+'px',
'background-color': color
});
// make position sensitive to size and document's width
var posx = (Math.random() * ($(document).width() - divsize)).toFixed();
var posy = (Math.random() * ($(document).height() - divsize)).toFixed();
$newdiv.css({
'position':'absolute',
'left':posx+'px',
'top':posy+'px',
'display':'none'
}).appendTo('body').fadeIn(500).delay(1000).fadeOut(500, function(){
$(this).remove();
makeDiv();
});
})();
//Score
window.onload = function() {
var a =0;
function
myFunction()
{
a= a +1;
document.getElementById('demo').textContent=a;
}
document.getElementById('button').onclick = myFunction;
}
popup.html
<html>
<head>
<meta charset="utf-8">
<script src="background.js"></script>
<script src="jquery-1.11.3.min.js"></script>
<style>
#score{
position:absolute:
margin:auto;
left:0px;right:0px;top:40px;
width:100%;height:10px;
text-align:center;
font-size:160%;
}
</style>
</head>
<body style="width:400px;height:500px;">
<script src="popup.js"></script>
<div id="score">
<p>Score:</p>
<p id="demo"></p>
<div>
</body>
</html>
我知道这很可能是一个愚蠢的错误,但我似乎无法弄清楚。该分数将计入第一个按钮,但不包括其余部分。