好的,我有以下功能和 HTML 来配合它,它完全可以工作,但是我希望添加扩展功能。我想知道是否可以使用屏幕上弹出的 close_game 函数来制作一个表单?
上图中模糊的是我无法显示的 secret 信息,但我想知道是否在“您确定要关闭游戏吗?”之间。和“此操作无法撤消。”我可以在那里放置一个表单,然后当右侧按钮中的“关闭游戏”按钮时,该表单将被提交并将信息放入数据库中。
有谁知道有什么好方法可以做到这一点,或者这是否可能? (需要注意的是这个网站是基于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();
}
});
});
}
最佳答案
你的意思是这样吗?
<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>
关于javascript - 在 JavaScript 函数中创建表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25396540/