Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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 如何显示使用jQuery load()将多个项目ajax到多个元素中?_Javascript_Ajax_Jquery_Jquery Load - Fatal编程技术网

Javascript 如何显示使用jQuery load()将多个项目ajax到多个元素中?

Javascript 如何显示使用jQuery load()将多个项目ajax到多个元素中?,javascript,ajax,jquery,jquery-load,Javascript,Ajax,Jquery,Jquery Load,我需要将某个项目从一个大页面加载到页面的不同元素中。我写的代码正在工作,但是项目一个接一个地加载,并且经过了大量的暂停。我想我可能做得不对,因为我不是一个完整的开发人员,只是一个设计师 我的代码看起来像: $("#lot-rental").load("/est.html #est-rental"); $("#lot-deposit").load("/est.html #est-deposit"); $("#lot-date").load("/est.html #est-date"); $("#l

我需要将某个项目从一个大页面加载到页面的不同元素中。我写的代码正在工作,但是项目一个接一个地加载,并且经过了大量的暂停。我想我可能做得不对,因为我不是一个完整的开发人员,只是一个设计师

我的代码看起来像:

$("#lot-rental").load("/est.html #est-rental");
$("#lot-deposit").load("/est.html #est-deposit");
$("#lot-date").load("/est.html #est-date");
$("#lot-build").load("/est.html #est-build");
使用$.get加载数据,然后手动设置各个元素的内容

$.get('/est.html', function(data) {
    $.each(['rental', 'deposit', 'data', 'build'], function(i, key) {
        $('#lot-' + key).html($(data).find('#est-' + key));
    });
}, 'html');
使用$.get加载数据,然后手动设置各个元素的内容

$.get('/est.html', function(data) {
    $.each(['rental', 'deposit', 'data', 'build'], function(i, key) {
        $('#lot-' + key).html($(data).find('#est-' + key));
    });
}, 'html');
为什么不使用$.get解析响应找到元素并将其加载到主页面:

$.get('/est.html',function(html){
    //wrap in jQuery so we can use it as context
    html = $(html);

    //find the item in html, and append to the container in the current page
    $('#est-rental',html).appendTo('#lot-rental');
    //     ^          ^                  ^-- target
    //     |          '-- context
    //     '-- the element to find in HTML
});
为什么不使用$.get解析响应找到元素并将其加载到主页面:

$.get('/est.html',function(html){
    //wrap in jQuery so we can use it as context
    html = $(html);

    //find the item in html, and append to the container in the current page
    $('#est-rental',html).appendTo('#lot-rental');
    //     ^          ^                  ^-- target
    //     |          '-- context
    //     '-- the element to find in HTML
});
试试这个

$("#lot-rental").load("est.html#est-rental");
$("#lot-deposit").load("est.html#est-deposit");
$("#lot-date").load("est.html#est-date");
$("#lot-build").load("est.html#est-build");
试试这个

$("#lot-rental").load("est.html#est-rental");
$("#lot-deposit").load("est.html#est-deposit");
$("#lot-date").load("est.html#est-date");
$("#lot-build").load("est.html#est-build");

如果要逐个加载,也可以尝试此操作。$'result'.load'ajax/test.html',函数{$'result1'.load'ajax/test1.html',函数{};};如果要逐个加载,也可以尝试此操作。$'result'.load'ajax/test.html',函数{$'result1'.load'ajax/test1.html',函数{};};谢谢你的回答似乎是我在寻找的,但我已经尝试过了,在控制台中它说:data.find不是一个函数,我可以看到它加载html,但一些查找是如何工作的。谢谢你的回答似乎是我在寻找的,但我已经试过了,在控制台中,它说:data.find不是一个函数,我可以看到它正在加载html,但find是如何工作的。