我有一个id为#editor的div。在这个div中有一个class为.float-right的图片。我还动态地向#editor div添加了具有相同class的新图像。下面的jQuery代码适用于新添加的图像,但不适用于现有的图像。为什么?我需要两种方式都能使用。
HTML
<div id="#editor">
<img src="img.jpg" class="float-right">
<!--jQuery will select this image only if added after page load -->
</div>
jQuery
$('#editor').on('click', '.float-right', function() {
//Do stuff
});
我正在处理的草稿代码是http://jsfiddle.net/kthornbloom/9tdDa/(它是一个所见即所得的HTML5编辑器)。
.img-wrap-left #btn-done
表明你可能是。 - John Dvorak