这两者有什么不同:
$.each($('#myTable input[name="deleteItem[]"]:checked').do_something());
这是:
$('#myTable input[name="deleteItem[]"]:checked').each(function() { do_something });
正在 Select 并执行操作的表格单元格的html如下所示:
<td width="20px"><input type="checkbox" class="chkDeleteItem" name="deleteItem[]" value="' . $rowItem['itemID'] . '" /></td>
I've gone over the jQuery documentation, but I still don't understand the difference. (Is it me or is that documentation sometimes slightly "nebulous" in clarity of content?)
Added Info:
Apparently my attempt a generic examples is confusing people! Along with the (previously) missing parenthesis in the first example. :(
The first example comes from a line in my code that removes the <tbody> for any rows with a checkbox that is checked:
$.each($('#classesTable input[name="deleteClasses[]"]:checked').parent().parent().parent().remove());
第二个示例来自于这样一种情况:我在#classesTable中查找任何选中的复选框,并在下拉列表中删除其匹配项.
$('#classesTable input[name="deleteClasses[]"]:checked').each(function(){
$('#classesList option[value="' + $(this).attr('value') + '"]').remove();
});
I understand that they do two different things, but not to the point that I'd be able to say "I need to use $.each() in this case and .each(function() {}) in another case.
它们可以互换吗?只是在某些情况下?从不