2015-02-07 81 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

希望這會有所幫助!請標記爲答案,如果有的話!謝謝