使用按钮打开包含库存项目详细信息的页面



我的目的是在索引页面上显示带有链接的产品。单击链接时

我有一个链接到产品页面的按钮,但没有索引页面上的其他项目。

如何使用此链接打开每个产品页面?

按钮的代码:

<button type="button" class="btn btn-success" data-toggle="modal" data-target="#details-1">Details</button>

模态:

    <?php
include 'details-modal-item01.php';
include 'details-modal-item02.php';
?>

页面详细信息modal-item01.php或多或少是其他项目的模板:

<div id="item01" class="modal fade item01" tableindex="-1" role="dialog" aria-labelledby="details-1" aria-hidden="true"> -- rest of code goes here --</div>

任何帮助将不胜感激。

,而不是所有包含爵士乐,一旦您获得了许多产品,它将变得难以管理,您应该使用Ajax加载内容/部分或从JSON构建到模态 - 内容部分。p>好吧,说了然后说了,所以这是一个例子。


这是我通过使用ajax和partials的大规模做到的。

链接(S),您需要将data-url=""属性更改为指向部分。

<a href="javascript:void(0)" class="ajax-modal" data-url="/link/to/partial" data-size="modal-md" role="button" data-toggle="modal"><i class="fa fa-plus fa-fw"></i> Open Modal</a>

模态包装器。这将放在模板的底部,在</body>

之前
<div id="ajax-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Loading...</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true" aria-label="Close">×</button>
            </div>
            <div class="modal-body slow-warning"><p>Please wait...</p></div>
        </div>
    </div>
</div>

部分将从链接端点提供服务,您可以检查请求是ajax并显示部分,如果不显示完整页面。

<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Foo Bar</h4>
    </div>
    <div class="modal-body"></div>
</div>

然后jQuery ,它处理将内容加载到模态中。

<script>
    var ajax_modal = function(e) {
        e.preventDefault();
        $('#ajax-modal').modal('show');
        var modal = '.modal-content';
        var default_content = '' +
            '<div class="modal-header">' +
            '    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>' +
            '    <h4 class="modal-title">' +
            '        Loading...' +
            '    </h4>' +
            '</div>' +
            '<div class="modal-body">' +
            '    <p class="slow-warning">Please wait...</p>' +
            '</div>';
        $(modal).html(default_content);
        setTimeout(function() {
            if ($(document).find('.slow-warning').length > 0) {
                $(document).find('.slow-warning').html('Content failed to load, please refresh your browser and try again.');
            }
        }, 5000);
        //
        var dialog_size = $(this).data('size');
        if (dialog_size == 'modal-lg') {
            $(modal).parent().removeClass('modal-sm modal-md modal-lg').addClass('modal-lg');
        }
        else if (dialog_size == 'modal-sm') {
            $(modal).parent().removeClass('modal-sm modal-md modal-lg').addClass('modal-sm');
        }
        else {
            $(modal).parent().removeClass('modal-sm modal-md modal-lg').addClass('modal-md');
        }
        //
        var request = $.ajax({
            url: $(this).data('url'),
            method: "GET",
            dataType: "html",
            cache: false
        });
        request.done(function(data) {
            $(modal).replaceWith($('<div />').html(data).find(modal)[0]);
        });
        request.fail(function(jqXHR, textStatus) {
            console.log('modal failed to load', textStatus);
        });
    };
    $(document).find('.ajax-modal').off('click').on('click', ajax_modal);
</script>

相关内容

最新更新