Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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 如何在不重新加载的情况下返回特定页面?_Javascript_Jquery_Html_Mobile - Fatal编程技术网

Javascript 如何在不重新加载的情况下返回特定页面?

Javascript 如何在不重新加载的情况下返回特定页面?,javascript,jquery,html,mobile,Javascript,Jquery,Html,Mobile,我正在尝试使用Javascript开发一个移动应用程序。我想做一个链接,允许您返回到一个特定的网页,已经访问,而无需重新加载此网页 我尝试使用以下代码: $('#ajouter').live('click',function(e) { window.localStorage.setItem("phrase", $("label[for='" + ($('input[name=opt1]:checked').attr('id') ) + "']").text()); //Id Rubriq

我正在尝试使用Javascript开发一个移动应用程序。我想做一个链接,允许您返回到一个特定的网页,已经访问,而无需重新加载此网页

我尝试使用以下代码:

$('#ajouter').live('click',function(e) {
  window.localStorage.setItem("phrase", $("label[for='" + ($('input[name=opt1]:checked').attr('id') ) + "']").text());
  //Id Rubrique
  $.mobile.changePage('../z.html');
});
$("#z").live('pageshow', function() {
  .....
}

但是它会让我重新加载页面。

使函数返回false以避免重新加载页面的默认行为使用以下方法:

$('body').on('click','#ajouter',function(e) {
   e.preventDefault(); // stops default behaviour ie reloading
  ...
还建议更改on()函数而不是live()

注意:如果您使用的是1.8之前的jQuery版本,则保留问题中的live()处理程序,只需添加默认值:

$('#ajouter').live('click',function(e) {
   e.preventDefault();

只是想一想——如果您使用的是jQuery>1.7,那么live()是一个不推荐使用的函数,那么跨设备和跨操作系统优化可能会让您省去很多麻烦。改为使用on()处理程序…@jtheman:我应该像这样更改我的页面代码
$(“#z”)。on('pageshow',function(){…}
No使用live()等效的使用$(document)。on('pageshow','#z',function()-或将'document'限制在更近的父级element@jtheman
$(document).on('pageshow','#z',function(){…}
使用此代码,我的页面不会刷新?如何编写函数?
$('body')。在('click','ajouter',函数(e){e.preventDefault();//停止默认行为ie reloa window.localStorage.setItem('phrase',$)('label[for='”+($('input[name=opt1]:checked')).attr('id'))+“])。text());//Id Rubrique$.mobile.changePage('../prestation_html/etape'+window.localStorage.getItem(“Id_grp”)+'.html');}
`
$(文档)。在('pageshow','#A1',function(){…}
上,将函数中的最后一条语句设置为return false;现在:(我有新问题:(包含按钮ajourner的页面(第2页)contained是动态添加的,我的问题是当我再次回到第2页时,第2页显示上一页,而不更改所包含的
$('body')。on('click','#ajour',function(e){e.preventDefault();//停止默认行为ie reloa window.localStorage.setItem(“短语”,$('label[for='”+($)input[name=opt1]:checked').attr('id')+“]”).text();//id Rubrique$.mobile.changePage('../prestation_html/etape'+window.localStorage.getItem('id_grp')+'.html');}
`
$(文档)。在('pageshow','A1',function(){…}
应该可以工作,但只需将e.preventDefault()添加到以前的代码中(单击处理程序)…是的,我们的上一个代码很好,但是现在:(我有了新问题:(包含按钮
ajouter
(第2页)的页面)包含是动态添加的,我的问题当我再次在第2页返回时,第2页显示上一页而不更改包含的内容可能需要为此添加一个新问题和新代码。我很难看到您的问题并在评论中进行讨论…请将此标记为您建议的答案,这是您表示感谢的方式你在这里这么。。。