我使用下面的代码通过Ajax调用保存多个可排序列表的顺序,并且由于某种原因它每次点击多次运行该调用。如果#resedit div中有两个列表,我会收到4到8个警报。jQuery嵌套.each()获取函数的外部
我不明白为什么ajax调用或警报将被多次执行...... .each函数中发生的唯一事情是构建一个变量,并且在发生其他任何事情之前它们完全关闭。
任何人都可以看到我要去哪里错了吗?
var listorder = '';
$('#resedit').children().each(function(index) {
if ($(this).css('display') != 'none' && $(this).attr('id') != '') {
listorder = listorder + $(this).attr('id') + ', ';
$(this).children().each(function(indexchildren) {
if ($(this).css('display') != 'none' && $(this).attr('id') != '') {
listorder = listorder + $(this).attr('id') + ', ';
placeholder = indexchildren;
}
});
}
});
var data = {
action : 'save_res',
security : '<?php echo $saveres_nonce; ?>',
resorder : listorder,
resumeslug : $('#res-dash-select').val(),
}
jQuery.post(ajaxurl, data, function(response) {
alert(response);
return;
});
});
还有一个'});'在最后,这导致我相信这里面有更多的代码。是否还有其他东西,这是包裹在或只是不需要'})'。 – 2011-05-29 20:38:34