Javascript没有将html加载到div中

时间:2013-11-29 15:52:30

标签: javascript jquery html load

为什么这不起作用?它应该将另一个html文件的内容加载到底部id为

的DIV中
<!DOCTYPE html>
<html lang="en">
  <head>
    <script type="text/javascript">
function loadContent(href, container){
  $wrapper = $('<div>'); 
  $wrapper.addClass('loaded_content_wrapper').appendTo(container).load(href, function(){
    $(this).animate({marginLeft:0}, 'slow').prevAll().animate({marginLeft:'-100%'}, 'slow', function(){
      $(this).remove();
    });
  })
}
    </script>
  <link href="style.css" rel="stylesheet" type="text/css">
  </head>

<div onClick="loadContent('hello-world.html', $('#bottom'))">Home</div>
<div id="bottom">
ramkaramka
</div>

</html>

1 个答案:

答案 0 :(得分:1)

如果为jquery.js添加脚本标记并设置jquery.js,hello-world.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript">
function loadContent(href, container){
    $wrapper = $('<div>'); 
    $wrapper.addClass('loaded_content_wrapper').appendTo(container).load(href, function(){
        $(this).animate({marginLeft:0}, 'slow').prevAll().animate({marginLeft:'-100%'}, 'slow', function(){
            $(this).remove();
        });
    })
}
        </script>
    <link href="style.css" rel="stylesheet" type="text/css">
    </head>

<div onClick="loadContent('hello-world.html', $('#bottom'))">Home</div>
<div id="bottom">
ramkaramka
</div>

</html>