使用foreach理解jQuery选择器

使用foreach理解jQuery选择器,jquery,foreach,jquery-selectors,Jquery,Foreach,Jquery Selectors,我很难理解为什么我的选择器不能为foreach循环工作 我的DOM看起来是这样的: <div id="page1" class="ui-droppable"> <div class="ui-draggable ui-draggable-handle ui-draggable-dragging signatureInstance selected btn-delete" style="position: absolute; left: 185px; top: 470px

我很难理解为什么我的选择器不能为foreach循环工作

我的DOM看起来是这样的:

<div id="page1" class="ui-droppable">

    <div class="ui-draggable ui-draggable-handle ui-draggable-dragging signatureInstance selected btn-delete" style="position: absolute; left: 185px; top: 470px;">
        <img src="http://example.com/img/field.png">
        <span class="glyphicon glyphicon-remove btn-delete"><span></span></span>
    </div>

    <div class="ui-draggable ui-draggable-handle ui-draggable-dragging signatureInstance selected btn-delete" style="position: absolute; left: 171px; top: 562px;">
        <img src="http://example.com/img/field.png">
        <span class="glyphicon glyphicon-remove btn-delete"><span></span></span>
    </div>

</div>

甚至:

$('#page1 div').forEach(function(index) {
    console.log($(this));
});
您需要使用来迭代jQuery对象,它是为它构建的

.each()方法旨在使DOM循环构造简洁且不易出错。调用时,它会迭代作为jQuery对象一部分的DOM元素。每次回调运行时,都会从0开始传递当前循环迭代。更重要的是,回调是在当前DOM元素的上下文中触发的,因此关键字this引用元素。(摘自)

用于迭代数组而不是jQuery对象集合

$('#page1 .signatureInstance').each(function(index) {
    console.log($(this));
});

为了更好地理解,我觉得自己很傻。非常感谢。我真的很感谢你的帮助@内森·夏克泰克:很高兴能帮忙
$('#page1 div').forEach(function(index) {
    console.log($(this));
});
$('#page1 .signatureInstance').each(function(index) {
    console.log($(this));
});