【问题标题】:How can I render a form after a button is clicked in Colorbox?在 Colorbox 中单击按钮后如何呈现表单?
【发布时间】:2012-03-22 08:01:02
【问题描述】:

我正在尝试在 Colorbox 中实现一个按钮,该按钮将更新模式并呈现表单。

Pinterest 的添加功能就是一个例子。 "Homepage > Add a Pin > Pin URL"

我尝试复制 Colorbox 的内联 HTML 示例。

<script type="text/javascript">
$(document).ready(function () { 
    $(".inline").colorbox({inline:true, width:"50%"});

    $('a[rel="colorbox"]').live("click", function() {

    $.colorbox({
        open: true,
        href: this.href
    });

    return false;
    });
});
</script>

        <div style='display:none'>
            <div id='inline_content' style='padding:10px; background:#fff;'>
            <p><strong>Add a Promotion</strong></p>
            <p><a id="click" href="#" style='padding:5px; background:#ccc;'>Click me, it will be preserved!</a></p>
            <p><strong>If you try to open a new ColorBox while it is already open, it will update itself with the new content.</strong></p>
            <p>Updating Content Example:<br />
            <a class="ajax" href="**shared/promotion_form**" rel="colorbox">Add a Promotion</a></p>
            </div>
        </div>

问题是表单是_promotion_form.html.erb,所以我无法链接到它。

【问题讨论】:

    标签: javascript jquery render colorbox


    【解决方案1】:

    尝试将选择器上移一个级别,并更新到 jQuery 1.7.1 也许是这样的:

    $('body').on("click", "a[rel="colorbox"]", function() {

    因此,您可以通过这种方式查看具有该选择器“a[rel='colorbox']”的任何元素的正文。

    希望这会有所帮助。

    【讨论】:

    • 选择器现在可以工作了。我遇到的问题是我不知道如何呈现促销表单而不是通过 href 链接。
    • 哦....只需使用 html 属性而不是 href 属性,值将是字符串或 jQuery 对象。
    猜你喜欢
    • 1970-01-01
    • 2018-05-27
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多