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个孩子。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...