2017-03-05 49 views
0

$.mobile.loadPage('view-video');不起作用,並且我有示例代碼下面。請幫我解決這個問題。

我收到警報「功能觸發」

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> 
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> 
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
</head> 
<body> 

<div data-role="page" id="index"> 
    <div data-role="header"> 
    <h1>Welcome To My Homepage</h1> 
    </div> 

    <div data-role="main" class="ui-content"> 
    <p>I Am Now A Mobile Developer!!</p> 
    <a href="javascript:void(0)" class="loadVideo">Load Video</a> 
    </div> 

    <div data-role="footer"> 
    <h1>Footer Text</h1> 
    </div> 
</div> 

<div data-role="page" id="view-video"> 
    <div data-role="main" class="ui-content"> 
    Your Video Will be Here. 
    </div> 
</div> 

<script type="text/javascript"> 
    $(document).on('click', '.loadVideo', function(e){ 
     alert('Function Triggered'); 
     $.mobile.loadPage('view-video'); 
    }); 
</script> 
</body> 
</html> 

回答

1

首先documentation says

注:jQuery.mobile.loadPage被棄用的jQuery移動1.4.0和會在1.5.0中刪除。改爲使用pagecontainer小部件的load()方法。

明白了吧working in this Fiddle帶JavaScript。而不是$(':mobile-pagecontainer').pagecontainer('load', "view-video);它必須是$(':mobile-pagecontainer').pagecontainer('change', "#view-video");! (change而不是負荷因爲它是一個id)

查看詳細說明,請參閱jQuery Mobile Demos。 重要的是,每個頁面都有它data-role="page"屬性=>jQuery Mobile Tutorial

+0

現在我已將代碼更改爲$(「:mobile-pagecontainer」)。pagecontainer(「load」,「view-video.php」);仍然不工作 – rkaartikeyan

+0

** view-video.php **是錯誤的,它必須是「頁面」的ID,所以沒有**。php ** =>編輯我的答案 – Michael

+0

https://jsfiddle.net/ bnkb0fuk/2 /請看看 – rkaartikeyan