如何用 ajax 调用替换引导框内容?
How can I replace a bootbox content with ajax call?
我是新来的,只会说一点英语。对不起,如果我写错了。
我正在使用引导框对话框并尝试在同一模式中显示 ajax 响应,但我做不到。有人可以帮我吗?哪种方法最好?
我有一个带有登录名的页面 link。当有人点击那里时,我会在引导框对话框中显示该表单,此表单有一个 link,如 "Don't have account? click here",我的想法是在同一引导框对话框中显示另一个表单
我试过了:
$(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());
});
非常感谢您的帮助!
您可以使用由 HTML 组成的字符串在您的 bootbox 中设置 HTML。然后你可以在打开bootbox后修改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 字符串具有可以在两者之间交换的类似制表符的结构。
我是新来的,只会说一点英语。对不起,如果我写错了。
我正在使用引导框对话框并尝试在同一模式中显示 ajax 响应,但我做不到。有人可以帮我吗?哪种方法最好?
我有一个带有登录名的页面 link。当有人点击那里时,我会在引导框对话框中显示该表单,此表单有一个 link,如 "Don't have account? click here",我的想法是在同一引导框对话框中显示另一个表单
我试过了:
$(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());
});
非常感谢您的帮助!
您可以使用由 HTML 组成的字符串在您的 bootbox 中设置 HTML。然后你可以在打开bootbox后修改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 字符串具有可以在两者之间交换的类似制表符的结构。