Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery单页移动应用程序_Javascript_Jquery_Html_Dom - Fatal编程技术网

Javascript jQuery单页移动应用程序

Javascript jQuery单页移动应用程序,javascript,jquery,html,dom,Javascript,Jquery,Html,Dom,我正在尝试构建一个具有多个页面的jQuery应用程序。在不同的html文件中放置不同的页面。 index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Dynamic Page Example</title> <meta name="viewport" content="widt

我正在尝试构建一个具有多个页面的jQuery应用程序。在不同的html文件中放置不同的页面。 index.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>
<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>
我不明白我哪里做错了。当没有javascript im abc.html时,它就会工作,但当我尝试使用js时,它只显示加载


任何帮助都会很好……

首先,我很抱歉,因为我在

<sciprt src="abc.js"></sciprt>
但那时候不行,我用

$('#second').html(msg.second);
$('#first').html(msg.first);
这就解决了我的问题。
当您通过
$.load()加载页面时,也不要在页面中使用
document.write()
。我为此浪费了3天(感谢@Ram指出这一点)。检查abc html中的

,您是否在var msg之前定义了html?如果是这样,只需将定义msg的脚本放在html标记之前。你有内联脚本(总是很糟糕),它需要初始化这个变量……我认为这是jquery mobile的一个问题,试着用jquery append()将值插入div,而不是Javascript。我不明白你在说什么。我想在同一个DOM中加载abc.html
$('#second').append(msg.second)但获取未定义的
msg
错误。我正在abc.html
中添加这些行–请重新阅读
<script src="abc.js"></script>
$('#second').append(msg.second);
$('#first').append(msg.first);
$('#second').html(msg.second);
$('#first').html(msg.first);