Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在更新记录时,根据记录显示的div数_Javascript_Jquery - Fatal编程技术网

Javascript 在更新记录时,根据记录显示的div数

Javascript 在更新记录时,根据记录显示的div数,javascript,jquery,Javascript,Jquery,当我要插入记录时,我可以插入多个记录。当我点击addmore时,我已经添加了addmore按钮,它在jquery的帮助下创建了克隆,这里是我的代码 $(document).ready(function () { //alert("auction-company"); var divLength = 1; var locationLength = 2; $("#addMore").on('click', function () { //alert("

当我要插入记录时,我可以插入多个记录。当我点击addmore时,我已经添加了addmore按钮,它在jquery的帮助下创建了克隆,这里是我的代码

$(document).ready(function () {
    //alert("auction-company");
    var divLength = 1;
    var locationLength = 2;
    $("#addMore").on('click', function () {
        //alert("auction-company");
        var cloneObj = $('.toClone').clone().removeClass('toClone');
        $(cloneObj).attr('id', 'addLocations' + divLength);
        $(cloneObj).find('span[id="locationCounter"]').attr('id', 'locationCounter' + locationLength).html(locationLength);
        /* for element ids increment starting */
        $(cloneObj).find('input[id="auctionLocationName0"]').attr('id', 'auctionLocationName' + divLength).val('');
        $(cloneObj).find('input[id="auctionLocationAddress0"]').attr('id', 'auctionLocationAddress' + divLength).val('');
        $(cloneObj).find('input[id="auctionLocationCity0"]').attr('id', 'auctionLocationCity' + divLength).val('');
        $(cloneObj).find('select[id="auctionLocationState0"]').attr('id', 'auctionLocationState' + divLength).val('');
        $(cloneObj).find('input[id="auctionLocationZipcode0"]').attr('id', 'auctionLocationZipcode' + divLength).val('');
        $(cloneObj).find('input[id="auctionLocationPhone0"]').attr('id', 'auctionLocationPhone' + divLength).val('');
        /* for element ids increment ending */
        $(cloneObj).find('div[class="tools"] a[id="firstRowRemoveDisable"]').addClass('remove');
        $("#toAppend").append(cloneObj);
        divLength++;
        locationLength++;
    });
});
它工作得很好,但是当我使用jqueryajax进行更新时,如何显示2个div及其记录呢。jQuery ajax和数据类型是json。这是我的更新代码

var auctionComapnyLocation = data.auctionResponseArray;
for (var auctionCompanyLocationLoop = 0; auctionCompanyLocationLoop < auctionComapnyLocation.length; auctionCompanyLocationLoop++) {
    $("#addLocations" + auctionCompanyLocationLoop).show(); 

    var cloneObj = $("#addLocations" + auctionCompanyLocationLoop).clone();
    $(cloneObj).removeClass('toClone');
    $(cloneObj).find('div[class="tools"] a[id="firstRowRemoveDisable"]').addClass('remove');
    //$(cloneObj).find('span[id="locationCounter"]').attr('id', 'locationCounter' + auctionCompanyLocationLoop).html(auctionCompanyLocationLoop);
    $("#toAppend").append(cloneObj);
    //$("#auctionLocationName").val(data.auctionResponseArray.auctionLocationName);
    /*$("#auctionLocationName").val(data.auctionResponseArray.auctionLocationName);
    $("#auctionLocationAddress").val(data.auctionResponseArray.auctionLocationAddress);
    $("#auctionLocationCity").val(data.auctionResponseArray.auctionLocationCity);
    $("#auctionLocationState").val(data.auctionResponseArray.auctionLocationState);
    $("#auctionLocationZipcode").val(data.auctionResponseArray.auctionLocationZipcode);
    $("#auctionLocationPhone").val(data.auctionResponseArray.auctionLocationPhone);
    */

}

你能把这个放到一个jsfiddle中吗;它会让你的问题在大多数情况下得到正确的回答。另外,你必须更具体地回答你的问题,为什么所有的赋值都被注释掉了?现在在编辑时,我可以看到div,但是有0个id,虽然我使用了循环变量,但它不起作用,id必须像0 1,但它在两个div var cloneObj=$addLocations+auctioncompanycationloop.clone上都显示0;