【问题标题】:How to capture div content and display within a modal box?如何捕获 div 内容并在模态框中显示?
【发布时间】:2014-07-20 17:47:24
【问题描述】:

当用户点击 html 页面上的图像时,下面会使用 jquery 来捕获该图像,然后在模态弹出框中显示它。

我现在还想捕获一个 div 的内容以传递给这个模态框。

我尝试添加以下$(this).width(100).height(100).appendTo('#badgeselect');,但这似乎不起作用,我错过了什么?

(我已将 .go 类添加到包装器 div 中)

               $( ".wrapper" ).on('click', 'wrapper');
               $(this).width(100).height(100).appendTo('#badgeselect_b');

现有代码

$(document).ready(function() {
    $('.go').css('cursor', 'pointer');
    $('.go').on('click', 'img', function(e) {
        $(this).width(100).height(100).appendTo('#badgeselect');
        $('#modal').reveal({
            animation: 'fade',
            animationspeed: 600,
            closeonbackgroundclick: true,
            dismissmodalclass: 'close'
        });
        return false;
    });
});

【问题讨论】:

  • 你可以创建 jsfiddle 吗?

标签: javascript jquery html


【解决方案1】:

http://jsfiddle.net/m2AJs/1/ : 举个例子


如您所说,要捕获内容,您可以使用以下方法:

1. .text() : http://api.jquery.com/text/

这将为您提供 div 的文本内容。

如果您只需要文本,请使用它。

例如:$("#modalDivId").text($("#divID").text());


2. .html() : http://api.jquery.com/html/

这将为您提供原样的 div,即其中包含任何格式、标签或元素。

如果您还需要 , , 等元素,请使用它。

例如:$("#modalDivId").html($("#divID").html());

【讨论】:

    【解决方案2】:

    从一个 div 中捕获文本并显示另一个 div 的示例教程 Sample

    <div id="Content">Hellooo World !</div>
    <br/>
    <br/>    
    <br/>
    <div id="modal"></div>
     <script>
     $('document').ready(function(){
     $('#Content').on('click',function(){
      var text = $(this).text();
     $('#modal').html(text)
     });
    });
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多