【问题标题】:How can I replace a bootbox content with ajax call?如何用 ajax 调用替换引导箱内容?
【发布时间】:2015-02-27 00:26:17
【问题描述】:

我是新来的,只会一点点英语。对不起,如果我有一些错误的写作。

我正在使用引导框对话框并尝试在同一模式中显示 ajax 响应,但我做不到。有人可以帮我吗?哪种方法最好?

我有一个带有登录链接的页面。当有人点击那里时,我会在引导框对话框中显示该表单,此表单有一个链接,例如“没有帐户?单击此处”,我的想法是在同一个引导框对话框中显示另一个表单

我试过这个:

$(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());
 });

非常感谢您的帮助!

【问题讨论】:

    标签: jquery ajax twitter-bootstrap bootbox


    【解决方案1】:

    您可以使用由 HTML 组成的字符串在 bootbox 中设置 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 字符串。

    【讨论】:

    • 谢谢你,让我检查一下。有了这个,我真的不会修改任何关于 bootbox 的东西。我没有想到这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多