javascript - 提交表单仅使用 Javascript 显示
问题描述
我使用 Phaser 制作了一款游戏,并希望我的用户能够在一个表单中填写他们的姓名,其中包含一个“姓名:”字段,然后单击提交按钮,提交他们刚刚输入的姓名和他们的高分。
这是我的javascript页面代码:
Game.Leader = function(game) {
buttonContinue = null;
state = null;
};
Game.Leader.prototype = {
create: function() {
this.showLeader();
},
showLeader: function() {
this.game.add.sprite(0, 0, 'screen-leader');
this.game.add.sprite(640-213-70, 80, 'spread');
this.state = 'Leader';
this.buttonContinue = this.add.button((640-200)/2, 960-103-1, 'button-restartsmall', this.startGame, this);
this.game.add.button(640-213-10, 20, 'twitter', function() {window.open("https://www.xxxxxxxx.com/", "_blank");}, this);
this.game.add.button(640-133-10, 20, 'whatsapp', function() {window.open("https://www.xxxxxxxx.com", "_blank");}, this);
this.game.add.button(640-293-10, 20, 'face', function() {window.open("https://www.xxxxxxxx.com", "_blank");}, this);
this.game.add.button(640-194-265, 700, 'button-leader2', function() {window.open("leader.htm", "_self");}, this);
this.game.add.sprite(640-194-220, 300, 'highscore-text');
highscoreText = this.game.add.text(290, 360, "0", { font: "40px ComicBook", fill: "#FFCC00", align: "right" });
storageAPI.initUnset('highscore',0);
var highscore = storageAPI.get('highscore');
highscoreText.setText(highscore);
},
startGame: function() {
this.game.state.start('Game');
}
};
所以他们的高分已经保存在下面的变量中,并在上面的页面上输出
var highscore = storageAPI.get('highscore');
我想抓住这个并通过在上面的脚本中添加一些东西来以表格的形式提交他们的名字——但是什么?
在提交表单时,需要执行以下函数以将其发布到 app42 排行榜服务 - 请参阅我的两个//评论:
function saveScore(n){
if(n){
var gameName = "xxxxx";
var userName = name; //this is where the name would go from the form
if(userName == ""){
userName = "Guest";
}
var gameScore = x; //what needs to go here to grab the highscore text already available?
var result;
var scoreBoardService = new App42ScoreBoard()
scoreBoardService.saveUserScore(gameName,userName,gameScore,{ success: function(object){} });
}
}
所以问题:
- 我需要添加第一个脚本来纯粹在 javascript 中添加表单吗?
- 我需要更改我的两个//评论在第二个脚本中的位置才能发布数据?
非常感谢您的帮助!
解决方案
推荐阅读
- c++ - 关于全局变量
- artifactory - 如何将基于文本的文件上传到 Artifactory,使其不添加 html-header?
- scroll - VS Code 中的快速文本滚动
- android - Azure 移动应用在后台同步
- inheritance - 我可以避免为从接口派生的类编写样板代码吗?
- c# - Azure 的 .NET Core 数据库连接错误
- javascript - 如何停止为值重复键
- python - Draw coordinates on edges of a map
- python - 如何使用 Python 在 Windows 中隐藏和取消隐藏特定文件或文件夹
- python - 你如何在 Python 中从标准输入读取单个字符