【问题标题】:Can you copy an existing div to a modal dialog您可以将现有的 div 复制到模态对话框吗
【发布时间】:2014-12-18 10:39:12
【问题描述】:

我有一个带有多个面板的仪表板来显示不同的信息,我希望能够添加一个按钮来以模式显示面板。

我正在使用引导程序,我能找到的只是已经编写好的模式。我想复制作为面板的 div 标签的内容,然后将其显示在模型中,但我不确定如何去做。面板的 html 如下所示。该面板确实包含一个表格,但我已经削减了代码。我环顾四周,但似乎找不到我需要的解决方案。我知道我需要使用 jQuery,复制面板并将其添加到模态对话框的内容中。我试过这样做,但没有运气。我已经包含了一个小提琴来展示我采用Here 的方法,这确实启动了模式,但没有显示内容,也没有显示关闭它的按钮。

任何帮助将不胜感激。

面板的 HTML 代码:

<div class="panel sample panel-yellow message">
    <div class="panel-heading">
        <h3 class="panel-title">
            <i class="fa fa-flask fa-fw"></i>Sample Updates 
            <i class="fa fa-spinner fa-spin sample "></i>
            <a id="refreshMessage" class="refreshButton pull-right" href="#"><span class="fa fa-refresh"></span></a>
            <a id="hideMessage" class="refreshButton pull-right" href="#"><span class="fa fa-arrow-up"></span></a>
            <a id="focusMessage" class="focusButton pull-right" href="#"><span class="fa fa-eye"></span></a>
        </h3>
    </div>
    <div class="panel-body">
        <center>
            <h5 class="text-warning">Table shows samples created or modified in the last ten minutes</h5>
        </center>
    </div>
</div>

我要显示的面板的屏幕截图:

【问题讨论】:

    标签: javascript jquery html twitter-bootstrap modal-dialog


    【解决方案1】:

    请试试这个

    <div class="panel sample panel-yellow message">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <i class="fa fa-flask fa-fw"></i>Sample Updates <i class="fa fa-spinner fa-spin sample ">
                            </i>
                            <a id="refreshMessage" class="refreshButton pull-right" href="#"><span class="fa fa-refresh"></span></a>
                            <a id="hideMessage" class="refreshButton pull-right" href="#"><span class="fa fa-arrow-up"></span></a>
                            <a id="focusMessage" class="focusButton pull-right" href="#"><span class="fa fa-eye"></span></a>
                        </h3>
    
                    </div>
                    <div class="panel-body">
                    <div class="table-responsive">
                        <table class="table table-condensed table-hover table-bordered table-responsive">
                            <thead>
                                <tr>
                                    <th>
                                        New Samples
                                    </th>
                                    <th>
                                        Modified Samples
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>
                                        <span class="sampleCount"></span>
                                    </td>
                                    <td>
                                        <span class="sampleCount2"></span>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </div>
                        <center>
                            <h5 class="text-warning">
                                Table shows samples created or modified in the last ten minutes</h5>
                        </center>
                    </div>
                </div>
    
    
    <div id="SampleModal" class="modal fade" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-body">
        </div>
    

    标记的唯一变化是我删除了隐藏类

    $('.focusButton').click(function(){
        var newRow = $(this).parent().parent().parent('.sample').clone();
        $('#SampleModal .modal-body').html(newRow);
        $('#SampleModal').modal();
    });
    

    检查这个小提琴:http://jsfiddle.net/hoja/qsbkqc9m/12/

    【讨论】:

      【解决方案2】:

      您可以使用以下代码实现此目的

      使用 JQuery:

      var html = $(id).html();
      

      使用 Javascript:

      var html = document.getElementById(id).innerHTML;
      

      希望这会有所帮助。

      【讨论】:

      • 这很明显,但我还是为了完整起见;他还需要为要从中复制 html 的 div 指定一个 id。
      猜你喜欢
      • 2011-07-28
      • 1970-01-01
      • 2011-09-22
      • 2014-10-07
      • 2011-12-03
      • 1970-01-01
      • 2016-10-29
      • 2012-09-24
      • 1970-01-01
      相关资源
      最近更新 更多