在javascript函数中创建表单?

时间:2014-08-20 04:02:57

标签: javascript php html laravel

好吧所以我有以下功能和HTML一起使用它完全正常工作但是我希望添加扩展功能。我想知道是否有可能使用屏幕上弹出的close_game函数显示一个表单?

http://i.imgur.com/FTBV5ee.png

上图中的模糊信息是我无法显示的机密信息,但我想知道是否介于“你确定要关闭游戏吗?”之间。并且“这个行动无法撤消。”我可以在那里放一个表格,而当按钮右边的关闭游戏按钮时,这个表格将被提交并将信息输入数据库。

有没有人知道这样做的好方法,或者甚至可能做到这一点? (需要注意的是这个网站是基于laravel框架的)

<div id="myModal_close" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close icon-remove" data-dismiss="modal" aria-hidden="true"></button>
        <h3 id="myModalLabel">Close Game</h3>
    </div>
    <div class="modal-body">
        <p>Are you sure you want to close the game <span id="modal-game-close-name"></span> (Serial Num: <span id="modal-game-close-serial"></span>) ?</p>
        <p>This action cannot be undone.</p>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
        <button id="confirm_close" data-dismiss="modal" class="btn btn-danger">Close Game</button>
    </div>
</div>


function close_game(game_name, serial) {
       $('#modal-game-close-name').html(game_name);
       $('#modal-game-close-serial').html(serial);
       $('#confirm_close').off('click.close_game').on('click.close_game', function() {
          $.ajax({
             url: '/game/' + serial + '/',
             type: 'PUT',
             success: function (data) {
                $('#alerts').html('<p class="alert alert-success">Successfully closed ' + serial + '</p>' + $('#alerts').html());
                $('#r' + serial).hide();
             },
             error: function (jqXHR, textStatus, errorThrown) {
                $('#alerts').html('<p class="alert alert-error">A problem occured while closing ' + serial + '</p>' + $('#alerts').html());
                $('#r' + serial).hide();
             }
          });
       });
    }

1 个答案:

答案 0 :(得分:0)

你的意思是这样吗?

<div id="myModal_close" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <div class="modal-header">
    <button type="button" class="close icon-remove" data-dismiss="modal" aria-hidden="true"></button>
    <h3 id="myModalLabel">Close Game</h3>
 </div>
<div class="modal-body">
<form id="myForm">
    <p><input type="text" id="username"></p>
    <p><input type="text" id="email"></p>
   <p><input type="password" id="password"></p>
</form>
   </div>
 <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
    <button id="submit" data-dismiss="modal" class="btn btn-danger">Submit</button>
 </div>
</div>