我在这里比较新,我只会说一点英语。对不起,如果我写错了。
我正在使用bootbox对话框并尝试在同一模式中显示ajax响应,但我不能这样做。有人可以帮我这个吗?哪种方法最好?
我有一个带登录链接的页面。当有人点击那里我在一个bootbox对话框中显示表单时,这个表单有一个链接,如“没有帐户?点击这里”,我的想法是在同一个bootbox对话框中显示另一个表单
我试过了:
$(document).on({
"show.bs.modal":function(e){
if($(".bootbox.in ").size()>0){
$(".bootbox.in ").removeData('bs.modal');
e.preventDefault();
}
$(".bootbox.in").children(".modal-content")
.html($(e.target).children(".modal-content").html());
});
非常感谢你的帮助!
答案 0 :(得分:1)
您可以使用由HTML组成的字符串在引导箱内设置HTML。然后,您可以在打开引导框后修改该HTML内的内容。
例如
// Nifty function that converts a comment to a string
var HTMLstring = (function () {/*
<div id="container">
<h1>Title</h1>
<div id="subcontainer">
LOGIN FORM HERE
<button id="createAccount"></button>
</div>
</div>
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
// Initialize bootbox with the above string
bootbox.dialog({
message: HTMLstring,
buttons:
{
"danger" :
{
"label" : "Close",
"className" : "btn-sm btn-danger",
"callback": function() {
}
}
}
});
// Here we attach the listeners to the above modal, to do what we want.
$('#createAccount').click(function() {
createAccountHTML = 'This can be your html for create account form';
$('#subcontainer').html(createAccountHTML);
});
或者,更好的选择而不是用javascript替换HTML是为了使原始HTML字符串具有可以在两者之间交换的类似标签的结构。