Jquery.load无法正常工作

时间:2015-02-22 18:16:15

标签: javascript jquery html css ajax

我希望topic.html加载(点击我的href时)代替div #courseDiv。我怎样才能做到这一点?我知道你必须使用Jquery.load但是如何使用?

JS:

$(document).ready(function(){
   $('#topics').click(function(){
      $('#contain').load('topics.html');
 });

HTML:

<div id = "courseDiv">
        <h1 class = "courseOptions" id = "choosetitle">Choose a title</h1>

        <h1 class = "courseOptions">Age group</h1>

        <h1 class = "courseOptions">What will you learn?</h1>

</div>

我的href:

<div id = "courseNavDiv">
            <ul class = "nav nav-list nav-stacked breadcrumbs col-md-2 col-lg-2" id = "courseNav">
                <li class = "disabled" id = "title"><a href="#">Title</a></li>
                <li id = "topics"><a href="#">Topic</a></li>
                <li><a href="#">Topic</a></li>
                <li><a href="#">Topic</a></li>
            </ul>
        </div>

2 个答案:

答案 0 :(得分:1)

$('#contain')更改为$('#courseDiv')并添加缺少的括号});

$(document).ready(function(){
   $("#topics").click(function(){
      $("#courseDiv").load("topics.html");
   });
});

答案 1 :(得分:0)

我猜您错过了代码中的}); ...

$(document).ready(function(){
   $("#topics").click(function(){
      $("#contain").load("topics.html");
   });
});