【问题标题】:Using Multi-page template by jquery mobile to display search result使用 jquery mobile 的多页模板显示搜索结果
【发布时间】:2012-05-15 20:36:59
【问题描述】:

这是我的 HTML 代码。我正在尝试的事情听起来很简单,但我做不到。我正在尝试使用 jquery mobile 建议的多页模板。第一页我有一个文本框和按钮。用户在文本框中输入一个值,然后单击应该将用户带到“page2”并显示搜索详细信息的按钮。

下面的代码将我带到“page2”,但我看不到任何搜索结果。我在两者之间插入了一个警报,并弹出了数据。 page2 上的后退按钮也不会将我带到 page1?

非常感谢任何指针。

<!DOCTYPE HTML>
    <html>
    <head>
    <title>Employee Finder</title>

    <script src="jquery-mobile/jquery-1.7.2.min.js"/>
    <script src="jquery-mobile/jquery.mobile-1.0a3.min.js"/>
    <script src="phonegap-1.3.0.js"/> 
    <script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"/>
    <link href="jquery-mobile/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css"/>

    <script> 

    $(document).ready(function() {
        $('#findemplyoee').click(function() {

          $.mobile.changePage('#page2', { transition: "slide", changeHash: true, reverse: true });

             var employeeNumber = $("#employeeNumber").val();
             var employeedetail = JSON.parse(... call a function here);

             if(employeedetail.found)
             {
                     $('#employeefirstName').text(employeedetail.firstName);
                     $('#employeelastName').text(employeedetail.lastName);
             }
             else
             {
                     $('#employeeDetails').html("<p>Sorry the employee Number you entered was not found!</p>");
             }

        });
    });

    </script>

    </head> 
    <body> 

    <div data-role="page" id="page1">
        <div data-role="header">
            <h1>Find Employee Data</h1>
        </div>

        <div data-role="content" id="searchDetails">    
           <input name="employeeNumber" type="text" id="employeeNumber"/>
           <input type="button" id="findemplyoee" data-theme="b" value="Find Employee"/>
        </div>

        <div data-role="footer">
            <h4>Page Footer</h4>
        </div>
    </div>

    <div data-role="page" data-add-back-btn="true" id="page2">
        <div data-role="header">
            <h1>Page Two</h1>
        </div>
        <div id="employeeDetails">
           <p id="employeefirstName"></p>
           <p id="employeelastName"></p>
        </div>
        <div data-role="footer">
            <h4>Page Footer</h4>
        </div>
    </div>

    </body>
    </html>

【问题讨论】:

    标签: html jquery-mobile


    【解决方案1】:

    您应该升级到 jQuery Mobile 1.1! 您的示例运行良好:http://jsfiddle.net/eUTga/

    我很确定您包含的 jQuery 版本 (jquery-mobile/jquery-1.7.2.min.js) 没有在旧的 jQuery Mobile (jquery-mobile/jquery.mobile-1.0a3.min. js) - 或者根本不兼容。

    请注意,jQuery Mobile 团队建议在 jQM 下载站点 (http://jquerymobile.com/download/) 上使用带有最新稳定版 (1.1.0) 的 jQuery 1.6.4。

    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
    

    【讨论】:

    • 太棒了!那确实有效,所以这是一个版本问题。我测试了您的 jsfiddle 解决方案并且效果很好。让我试试这个到我的本地。非常感谢“hna”
    • 是的!刚刚测试,它完美地工作。你让我的一天“hna”。再次感谢。
    猜你喜欢
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多