【发布时间】:2015-09-18 19:02:42
【问题描述】:
我是 javascript 新手,正在尝试编写 ping pong 代码,遵循过时/半错误的指南。 HTML 文件有一个消息框,此函数会在有人得分后写入该消息框。
function score(side) {
clearInterval(t);
msgBox = document.getElementById('messageBox');
msgBox.style.visibility = "visible";
scorePop = "<p> Point for the "+side+" side!<br/> ";
scorePop += "To serve the ball again, press \"s\" after closing this pop-up.</p>";
scorePop += "<a href="\"javascript:return false="" onclick="\prepNewGame('"left"');return"X Close</a>";
msgBox.innerHTML = scorePop;
}
传递的参数是“左”或“右”形式的获胜方。我知道问题出在倒数第二行代码中,因为如果我将其注释掉,我就可以运行其他所有内容。我相信字符串中的引号有问题,但我已经盯着这个看了太多小时了。虽然我不确定倒数第二行代码的用途,但我相信它应该出现在 msgBox 中,并带有一个“X Close”按钮并同时提示 prepNewGame。关闭后,用户可以按“s”开始新游戏。这是 prepNewGame 以防万一。
function prepNewGame(side) {
t=0;
msgBox.style.visibility='hidden';
theBall.style.top = "10px";
if(side == "left") {
theBall.style.left = "25px";
rpadl.style.top = "5px";
lpad.style.top = "5px";
} else {
theBall.style.left = (winWidth-40) + "px";
rpadl.style.top = "5px";
lpadl.style.top = "5px";
}
}
【问题讨论】:
-
这里
return"X你忘了关闭a标签
标签: javascript string onclick href