j查询单页移动应用程序

jQuery single page mobile app

本文关键字:应用程序 移动 单页 查询      更新时间:2023-09-26

我正在尝试构建一个具有多个页面的jQuery应用程序。不同的页面放置在不同的 html 文件中。索引.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Dynamic Page Example</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
    </head>
    <body>
        <sciprt src="abc.js"></sciprt>
        <div data-role="page" id="home" data-title="Welcome">
            <div data-role="header">
                <h1>Dynamic Page</h1>
            </div>
            <div data-role="content">
                <input type=button id="changePage" value="Open dynamic page">
                <!--<a href="abc.html" data-prefetch>abc</a>-->
            </div>
            <script>
                $("#changePage").on("click", function() {
                    // Create page markup

                    // Enhance and open new page
                    $.mobile.changePage('abc.html');
                });
            </script>
        </div>
    </body>
</html>

美国广播公司.html

<div data-role=page data-url=hi id=abc>
    <div data-role=header id=first>
        <h1>
           <script>
            document.write(msg.first);</script>
        </h1>
    </div>
    <div data-role=content id=second>
           <script>
            document.write(msg.second);</script>
    </div>
</div>

美国广播公司.js

var msg = {
    first : 'I am First',
    second : 'I am Second',
    third : 'I am Third'
};

我不明白我哪里做错了。当没有javascript im abc时.html那么它可以工作,但是当我尝试使用js时,它只是显示加载。

任何帮助都会很棒...

首先很

抱歉,因为我在

<sciprt src="abc.js"></sciprt>

应该是(感谢@Ingo伯克指出来)

<script src="abc.js"></script>

其次,我尝试使用

$('#second').append(msg.second);
$('#first').append(msg.first);

但是没有解决,然后我用了

$('#second').html(msg.second);
$('#first').html(msg.first);

这解决了我的问题。并且当您通过$.load()加载页面时,也不要在页面中使用document.write()。因此我浪费了 3 天(感谢@Ram指出)。检查 https://github.com/jquery/jquery-mobile/issues/430