尝试将新的html加载到div中时,load方法不起作用

时间:2014-08-10 03:42:23

标签: javascript jquery css html5 jquery-mobile

当我尝试使用jquery mobile进行编程时,我有一个问题是将新的html(在本地文件夹中)加载到div中。在脚本函数中,看起来像empty()工作casuse将清理maindiv中的先前内容。但是,新页面未加载到div中。它保持纯粹的白色空间。请帮忙。提前致谢。我使用的jquery移动版本是jquery mobile 1.4.3。非常感谢。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>ABC</title>
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,700">
    <link rel="stylesheet" href="./css/jquery.mobile-1.4.3.min.css">
    <link rel="stylesheet" href="./css/customizedstyle.css">
    <script src="./js/jquery.js"></script>
    <script src="./js/jquery.mobile-1.4.3.min.js"></script>
    <script>
        $( document ).on( "pagecreate", "#demo-page", function() {

            $( document ).on( "swipeleft swiperight", "#demo-page", function( e ) {
                if ( $( ".ui-page-active" ).jqmData( "panel" ) !== "open" ) {
                    if ( e.type === "swipeleft" ) {
                        $( "#right-panel" ).panel( "open" );
                    } 
                }
            });
        });
    </script>
    <style>
        #demo-page :not(INPUT):not(TEXTAREA) {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            -o-user-select: none;
            user-select: none;
        }
        /* Content styling. */
        dl { font-family: "Times New Roman", Times, serif; padding: 1em; }
        dt { font-size: 2em; font-weight: bold; }
        dt span { font-size: .5em; color: #777; margin-left: .5em; }
        dd { font-size: 1.25em; margin: 1em 0 0; padding-bottom: 1em; border-bottom: 1px solid #eee; }
        .back-btn { float: right; margin: 0 2em 1em 0; }
    </style>
</head>
<body>

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

    <div role="main" class="ui-content" id ="maindiv">



    </div><!-- /content -->

    <div data-role="panel" id="left-panel" data-theme="b">

        <p>&nbsp;</p>
        <a href="#" data-rel="close" class="ui-btn ui-corner-all ui-shadow ui-mini ui-btn-inline ui-icon-delete ui-btn-icon-left ui-btn-right">Close</a>

        <ul data-role="listview" data-icon="false" id="menu">

            <li>
            <a href="#" id = "btnservice" data-rel="close">Services<img id= "tmg" src="./images/iconb_service.png" class = "ui-li-thumb"/> 
            </a>
            </li>


        </ul>

    </div><!-- /panel -->

    <script type="text/javascript">
    $("#btnservice").on("click", function(){  

        $("#maindiv").empty();
        $("#maindiv").load("services.html");
    });

    </script>

</div><!-- /page -->

</body>
</html>

0 个答案:

没有答案