javascript - 如何在jquery mobile中单击按钮加载另一个html文件

标签 javascript jquery jquery-mobile cordova

我正在使用 jQuery 移动框架在 phonegap 中创建一个应用程序。

在我的 index.html文件我有两个文本框来接受用户名和密码。

当我点击提交按钮时,它调用了一个函数 submitBtn()检查用户名和密码是否正确,如果正确则应该加载我创建的新 html 文件 `selectOption.html'

这是我的代码

<script type="text/javascript">
    $(document).ready(function() {
        var userName;
        var userPassword;

        $("#submitBtn").click(function() {
            //alert("HI");       
            userName = $("#UserName").val();
            userPassword = $("#Password").val();

            if ((!UserName)|| (!userPassword)) {
                alert("Enter the Details");
            }
            else {
                if ((userName !="alpha") ||(userPassword !="beta")) {
                    alert('Enter correct username and password');
                }
                else {
                    //here i want to load my selectOption.html file ?
                }              
            }                                   
        });                           
    });
</script>

我的代码在 <body> 下是

<body>
    <div data-role="page" id="home">         
        <div data-role="header">             
            <h1>Enter Credential</h1>                       
        </div>

        <div data-role="content">
            <label for="UserName">User Name</label>
            <input type="text" name="UserName" id="UserName" value="" style="width:220px;"  />

            <label for="Password">Password</label>
            <input type="password" name="Password" id="Password" value="" style="width:220px;"  />

            <div id="submitBtn" data-role="button">Submit</div>
        </div>  
    </div>
</body>

正在调用该函数,但我该如何加载 selectOption.html文件?

最佳答案

您是否尝试过使用 jQuery Mobile 方法执行导航?

$.mobile.changePage("newpage.html");

http://jquerymobile.com/demos/1.0/docs/api/methods.html

关于javascript - 如何在jquery mobile中单击按钮加载另一个html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8727988/

相关文章:

javascript - 我需要向父 div 添加一个像素

javascript - 如何拆分数组中的字符串并将它们放置在 JavaScript 中的(新)二维数组中

javascript - 不使用默认命名空间/房间功能的 socket.io

jquery-mobile - 部分脚本未在 ASP.net MVC4 razor 中呈现

performance - 微调 HTML5 Phonegap 应用程序

javascript - Jquery 移动双范围 slider 重新加载新范围

javascript - 使用 AJAX 和 FormData 在 POST 上绑定(bind)列表

javascript - 在放置事件中将图像显示为无

php - 使用 jquery 将地理位置数据保存到 html 文件

php - jQuery 无法处理克隆的输入字段