0

我使用 jquery .load 函数从当前页面上的 div(page_content) 内的其他页面加载 divs(left) 但是当我使用 load 函数在 page_content 中加载另一个 div(right) 时,它会覆盖里面的所有内容div(页面内容)。我只想将它添加到 div 中。

这是我的代码:

function load(){ $('#page_content').load('test.php .left');}

function load2(){ $('#page_content').load('test2.php .right'); }

4

2 回答 2

1

您可以使用callback function to convert two call to single call and get the .left and right content in the call to assign to your element with id page_content,

$('#page_content').load('test.php', function(result){
  leftContent = $(result).find('.left').html();
  leftRight = $(result).find('.right').html();
  $(this).html($(leftContent + leftRight ).find('')
});
于 2012-11-23T11:02:47.517 回答
0

试试这个

function load(){ $('#page_content').load('test.php .left');}

$.ajax({
  url: 'test2.php .right',
  success: function(data) {
     $('#page_content').append(data);
  }
});
于 2012-11-23T11:06:43.043 回答