我的phonegap应用有问题。我有一个带有四个标题的导航栏,每个标题我都显示了同一个html文档的一部分。在最后一个标题中,我有一个保存四个标题中添加的数据,但我在第二个标题中有一些必填字段,我想在用户试图推动按钮保存数据和此字段时显示警告是空的。我希望在发生这种情况时显示警告消息,并且在我想要自动重定向到导航栏的第二个标题(它是同一个html文档的一部分)之后,用户必须完成必填字段。问题是我不知道如何重定向到这个表单,因为我知道如何使用命令“window.location.href('document.html')重定向到另一个html文档;”但不能重定向到同一个html文档的一部分。
我在这里放了一些我的代码:
导航栏的代码是:
<div data-role="tabs" id="tabs">
<div data-role="navbar">
<ul>
<li><a href="#one" data-ajax="false">Title 1</a></li>
<li><a href="#two" data-ajax="false">Title 2</a></li>
<li><a href="#three" data-ajax="false">Title 3</a></li>
<li><a href="#four" data-ajax="false">Title 4</a></li>
</ul>
</div>
<div id="one" class="ui-body-d ui-content">
...
</div>
<div id="two" class="ui-body-d ui-content">
...
</div>
<div id="three" class="ui-body-d ui-content">
...
</div>
<div id="four" class="ui-body-d ui-content">
...
</div>
andtom的代码是:
<input type="button" id="btnSave" name="btnSave" data-icon="star" data-theme="a" data- form="ui-btn-up-a" class=" ui-btn ui-btn-a ui-icon-star ui-btn-icon-left ui-shadow ui-corner-all" value="Save and end"/>
使用buttom调用的函数javascript的代码是:
$("#btnSave").on("click", function(){
if($("#fieldHeight").val() == "" || $("#fieldHeight").val() == null){
confirm("You must introduce your height to continue.");
window.location.href = 'index.html#two';
}else if($("#fieldWeight").val() == "" || $("#fieldWeight").val() == null){
alert("You must introduce your wheight to continue.");
}else if($("#fieldAge").val() == "" || $("#fieldAge").val() == null){
alert("You must introduce your age to continue.");
}else if(gend1.Gender == undefined){
alert("You must introduce your gender to continue.");
}else{...
}
}
问题是我使用“window.location.href ='index.html#two';”应用程序没有重定向到第二个标题但是当我只放“window.location.href ='index.html';”时它确定但在这种情况下,应用程序重定向到第一个标题。此外,我推动按钮和应用程序重定向之间存在非常大的延迟。
我希望有人可以帮助我并告诉我问题出在哪里或给我一个解决方案。非常感谢!!!
答案 0 :(得分:0)
如果您想重定向到相同的HTML,请使用以下代码
$.mobile.changePage("index.html#two");