Javascript $.mobile.changePage不工作

Javascript $.mobile.changePage不工作,javascript,jquery,jquery-mobile,Javascript,Jquery,Jquery Mobile,我正在尝试使用$.mobile.changePage,但它不起作用。 这是我的密码 <!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta charset="utf-8">

我正在尝试使用
$.mobile.changePage
,但它不起作用。 这是我的密码

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">    
         <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css">
         <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
         <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
    </head>
    <body>
        <div data-role="page" id="p1">
            <div data-role="header"><h2>DKT</h2></div>
            <div data-role="content">
                <div id="sw1"></div>
                <div id="sw2"></div>
            </div>
            <div data-role="footer">...</div>
        </div>
        <script>
            $.mobile.changePage("#qu");
        </script>
        <div data-role="page" id="qu">
            <div data-role="header"><h2>DKT</h2></div>
            <div data-role="content">
                <fieldset class="ui-grid-a">
                    <div class="ui-block-a"><button>Nein</button></div>
                    <div class="ui-block-b"><button>Kaufen</button></div>
                </fieldset>
            </div>
        </div>
    </body>
</html>

DKT
...
$.mobile.changePage(“#qu”);
DKT
不
购买
我已经收到错误
TypeError:“undefined”不是对象(计算'I.trigger')

我已准备好尝试更改为“”:仍然收到相同的错误

编辑:


谢谢大家。但问题实际上在我代码的另一部分。将jquery代码封装在
文档中。ready
处理程序,如下所示:

$(document).ready(function() {
   $.mobile.changePage("#qu");
});
否则,您将没有时间加载DOM,因此在尝试获取它时,
#qu
元素不存在。

请在之后添加脚本

 <div data-role="page" id="qu">

或者在body标签的末尾

像这样:

 <script>
             $.mobile.changePage("#qu");
         </script>


$.mobile.changePage(“#qu”);

如下更改代码

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">    
         <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css">
         <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
         <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
    </head>
    <body>
        <div data-role="page" id="p1">
            <div data-role="header"><h2>DKT</h2></div>
            <div data-role="content">
                <div id="sw1"></div>
                <div id="sw2"></div>
            </div>
            <div data-role="footer">...</div>
        </div>
        <script>
            $('#p1').live('pageshow', function(event){
                $.mobile.changePage("#qu");            
            });
        </script>
        <div data-role="page" id="qu">
            <div data-role="header"><h2>DKT</h2></div>
            <div data-role="content">
                <fieldset class="ui-grid-a">
                    <div class="ui-block-a"><button>Nein</button></div>
                    <div class="ui-block-b"><button>Kaufen</button></div>
                </fieldset>
            </div>
        </div>
    </body>
</html>

DKT
...
$('#p1').live('pageshow',函数(事件){
$.mobile.changePage(“#qu”);
});
DKT
不
购买
在您的代码中,
$.mobile.changePage(“#qu”)。您可以使用许多其他事件,如
pagebeforeshow
pagecreate
等。有关更多信息,请查看jQuery Mobile


确保您没有使用
$(doucment).ready(function(){})也是

在jQuery Mobile中使用
$(document).ready()
时存在风险。您可能应该在
pagecreate
pagebeforeshow
或类似的内容上绑定。