Jquery mobile 加载本地html文件时如何处理页面重定向?

Jquery mobile 加载本地html文件时如何处理页面重定向?,jquery-mobile,cordova,Jquery Mobile,Cordova,在我的HTML文件中: 在我的js文件中: $(函数(){ $(“#termsPage”).live('pagecreate',函数(事件,用户界面){ $(“#termDiv”).load(“tnc.html”).trigger('create'); }); }); 然后,在我的tnc.html文件中: 我似乎找不到任何解决方案在谷歌如何加载本地html页面正确。有人对此有建议/经验吗?我想直接显示单击的链接。您很接近,但还不够 .trigger('create')不能在加载函数后使

在我的HTML文件中:


在我的js文件中:

$(函数(){
$(“#termsPage”).live('pagecreate',函数(事件,用户界面){
$(“#termDiv”).load(“tnc.html”).trigger('create');
});
});
然后,在我的tnc.html文件中:



我似乎找不到任何解决方案在谷歌如何加载本地html页面正确。有人对此有建议/经验吗?我想直接显示单击的链接。

您很接近,但还不够

  • .trigger('create')不能在加载函数后使用。加载函数是异步的,所以我们需要等待成功状态触发pagecreate
  • 按钮示例将不显示,它需要关闭
  • 请勿使用pagecreate,在这种情况下pagebeforeshow
  • 下面是一个工作示例:

    index.html:

    <!DOCTYPE html>
    <html>
    <head>
        <title>jQM Complex Demo</title>
        <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
            <script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js"></script>        
        <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>    
        <script src="index.js"></script>
    </head>
    <body>
        <div data-role="page" id="index">
            <div data-theme="a" data-role="header">
                <h3>
                    First Page
                </h3>
                <a href="#second" class="ui-btn-right">Next</a>
            </div>
    
            <div data-role="content">
                        <div id="termDiv">
    
                        </div>
            </div>
    
            <div data-theme="a" data-role="footer" data-position="fixed">
    
            </div>
        </div>   
    </body>
    </html>   
    

    我希望这是您一直想要的。

    再说一次,您想加载它并稍后使用,还是想加载它并同时显示?您好,Gajotres,很抱歉,我需要删除另一个线程。。我想在点击链接后加载并显示它。。有什么建议吗?没问题,我会为你创建一个工作示例。thx Gajotres,我明天会尝试这个,希望会有好消息。。很抱歉,现在无法提供任何信息,因为我对JQuery Mobile非常陌生,因此如果不尝试,我无法完全理解您的代码:)
    <a href="http://www.google.com" data-role="button" rel="external">Onen link</a>
    
    $(document).on('pagebeforeshow', '#index', function(){       
        $("#termDiv").load("load.html", function(){
            $('#index').trigger('create');
        });  
    });