2015-02-07 72 views
0

我想加载一个外部的jquery移动页面在div但似乎不工作。加载外部jQuery的移动页面不工作

的index.html

<div data-role="page" id="page1"> 
    <div data-role="header"> 
    <h1>Header</h1> 
    </div> 
    <p><a class="followclick" href="#">Get the News</a></p> 
    <div id="content" data-role="content"></div> 
    <div data-role="footer"> 
    <h4>Footer</h4> 
    </div> 
</div> 

jQuery的

$(document).ready(function() { 
    $('.followclick').on('click', function(event) { 
     $('#content').load('news.php'); 

    }); 
}); 

news.php

<div data-role="page" id="page2"> 
    <div data-role="header"> 
    <h1>Header</h1> 
    </div> 
    <div id="news" data-role="content"></div> 
    <div data-role="footer"> 
    <h4>Footer</h4> 
    </div> 
</div> 
+0

您的'.followclick'元素在哪里? – 2015-02-07 09:16:35

+0

我刚刚编辑了这个问题。在里面 – 2015-02-07 09:20:33

回答

0

尝试使用jQuery.ajax({url:'news.php',type:'GET',success:function(resp){$('#content').html(resp);}})代替。

jQuery.load(....)可能无法与div一起使用。

jQuery加载可用于任何与URL相关的元素:图像,脚本,框架,iframe和窗口对象。它也不会工作/给跨域请求带来问题。

More info here

希望这会有所帮助!请标记为答案,如果有的话!谢谢