图像的 onClick() 事件我想动态创建 div 并将图像添加到该 div。动态创建的应该有背景颜色和一些文本请帮助。
这是更新的 Fiddle with Flip 方法 http://jsfiddle.net/RQ62f/7/
#foobar
{
background-color: red;
content: div is here;
}
in Jquery,
$(this).appendTo('#foobar');
请帮忙
最佳答案
在 jQuery 中:
$("img").click(function(){
alert('m called');
if ($('#foobar').length==0) $('<div id="foobar"></div>').appendTo('body');
$(this).appendTo('#foobar');
});
元素必须存在才能向其附加内容。
关于jquery - 添加图像动态创建的 div 以显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16413295/