提交仅使用Javascript显示的表单

提交仅使用Javascript显示的表单,javascript,phaser-framework,app42,Javascript,Phaser Framework,App42,我已经使用phaser制作了一个游戏,希望我的用户能够在表单上填写自己的名字,其中有一个“名字”字段,然后单击提交按钮,提交他们刚刚输入的名字和高分 以下是我的javascript页面代码: Game.Leader = function(game) { buttonContinue = null; state = null; }; Game.Leader.prototype = { create: function() { this.showLeader(); }, sh

我已经使用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添加表单的脚本
  • 为了发布数据,我需要更改第二个脚本中两条//注释的位置吗

  • 非常感谢您的帮助

    有没有什么特别的原因让你想/需要用JavaScript创建表单,而不是让表单已经在页面上并切换其样式/显示?这两种方法都可以,但我不知道如何在index.html中隐藏表单,并且只在显示的Leader状态下显示它