无法在jquery中添加类

我正在尝试将类(.trans)添加到我在jquery中新制作的克隆。 但它不起作用。 …当我将课程直接应用于我的对象时,它的工作完美。

我想做的是……

  1. 我从数据库中获取一些图像到我的页面。
  2. 与foreach循环我显示那些图像..
  3. 然后在jquery clone方法的帮助下,当我点击它时,我创建一个特定图像的克隆,克隆将显示在另一个div中。
  4. 现在我想为我新创建的克隆添加一个特定的类。 但它不工作..(注意:当我在同一个类上直接应用新鲜对象(不是克隆)时,它的工作时间)

仅供参考最终结果应该是这样但是在制作克隆之后.. http://jsfiddle.net/66Bna/293/

这是我的代码……

       $(document).ready(function(){ $(".my_image").click(function(){ $(this).clone().addClass("trans").appendTo(".block"); }); });   body{ user-select: none; -webkit-user-select: none; -moz-user-select: none; -o-user-select: none; -ms-user-select: none; } .shape{ width: 300px; height: 250px; background-color: #B2D237; color: #123456; } #bounds { position: absolute; border: 1px solid red; } .block{ width:100%; background:red; }    
    $img) { echo "
  • "; } ?>
$(function(){ // do a selector group $('.trans').freetrans({ x: 50, y: 50 }); //updating options, chainable $('#two').freetrans({ x: 200, y: 100, angle: 45, 'rot-origin': "50% 100%" }) .css({border: "1px solid pink"}) var b = $('#two').freetrans('getBounds'); console.log(b, b.xmin, b.ymax, b.center.x); $('#bounds').css({ top: b.ymin, left: b.xmin, width: b.width, height: b.height }) })

好的,看。 发生的事情是你在文档的末尾激活了Free Transform插件,而插件的所有function就是使用该类获取现有元素并为它们提供function。

当我们动态添加元素和类时,插件不会考虑它们,因为在调用插件时,元素不存在。

懂了吗?

所以,看到我没有适当的开发环境,我会建议一些可能的解决方案:

1)将此脚本放在Free Transform插件声明下方的底部

  

2)为每个添加的元素初始化插件编辑:修复了一些逻辑错误

  

试试吧