当用户点击 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;
});
});
最佳答案
<强> http://jsfiddle.net/m2AJs/1/ :以工作 fiddle 为例
<小时/>要捕获您所说的内容,您可以使用以下方法:
1. .text()
: http://api.jquery.com/text/
这将为您提供 div 的文本内容。
如果您只需要文本,请使用此选项。
例如:$("#modalDivId").text($("#divID").text());
2. .html()
: http://api.jquery.com/html/
这将使您按原样获得 div,即其中包含任何格式、标签或元素。
如果您还需要 、 、 等元素,请使用此选项。
例如:$("#modalDivId").html($("#divID").html());
关于javascript - 如何捕获div内容并在模态框中显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24848222/