如何解决jQuery嵌套.each超出函数
| 我正在使用以下代码通过Ajax调用保存多个可排序列表的顺序,由于某种原因,它每次点击都会多次运行该调用。如果#resedit div中有两个列表,我会收到4到8个警报。 我不明白为什么多次执行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;
});
});
解决方法
您的Ajax呼叫在(外部)
children().each()
呼叫之内。因此,每个ѭ2every div的直接子对象都将被调用一次。
而且我猜#resedit
div有4到8个孩子。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。