Javascript 使用JQuery Mobile在页面之间导航
我正在开发一个使用的应用程序。我的应用程序有3个屏幕,分别为两个单独的ASP.NET文件。这些屏幕为“第1页”、“第2-A页”和“第2-B页”。这些屏幕位于以下文件中: page1.aspxJavascript 使用JQuery Mobile在页面之间导航,javascript,jquery-mobile,navigation,Javascript,Jquery Mobile,Navigation,我正在开发一个使用的应用程序。我的应用程序有3个屏幕,分别为两个单独的ASP.NET文件。这些屏幕为“第1页”、“第2-A页”和“第2-B页”。这些屏幕位于以下文件中: page1.aspx Page 1 Page 2 - A Page 2 - B <!DOCTYPE html> <html> <head><title></title> <meta name="viewport" content="width=
Page 1
Page 2 - A
Page 2 - B
<!DOCTYPE html>
<html>
<head><title></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<link rel="stylesheet" href="/app.css" />
<script src="/resources/scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="/resources/scripts/jquery.mobile-1.0.1.min.js" type="text/javascript"> </script>
</head>
<body>
<form method="post" action="page1.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNDMyNDU0NjAzZGRwU4yeA9j5ta11sndZ5ttoGphlk//bQegtegJWNYp1Rg==" />
</div>
<div data-role="page">
<div data-role="header"><h1>Page 1</h1></div>
<div data-role="content">
<a href="page2.aspx" data-role="button">Page 2</a></div>
</div>
</div>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<link rel="stylesheet" href="/app.css" />
<script src="/resources/scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="/resources/scripts/jquery.mobile-1.0.1.min.js" type="text/javascript">
</script>
</head>
<body>
<form method="post" action="page2.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNDMyNDU0NjAzZGS9YWabTaXXRTn8y1t/9nyD4FvN9HRt1cI9c8W8lj21mw==" />
</div>
<div id="A" data-role="page">
<div data-role="header"><h1>Page 2 - A</h1></div>
<div data-role="content">
<a href="#B " data-role="button">B</a></div>
</div>
</div>
<div id="B" data-role="page">
<div data-role="header"><h1>Page 2 - B</h1></div>
<div data-role="content">
I can't get to this page!
</div>
</div>
</form>
</body>
</html>
page2.aspx
Page 1
Page 2 - A
Page 2 - B
<!DOCTYPE html>
<html>
<head><title></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<link rel="stylesheet" href="/app.css" />
<script src="/resources/scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="/resources/scripts/jquery.mobile-1.0.1.min.js" type="text/javascript"> </script>
</head>
<body>
<form method="post" action="page1.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNDMyNDU0NjAzZGRwU4yeA9j5ta11sndZ5ttoGphlk//bQegtegJWNYp1Rg==" />
</div>
<div data-role="page">
<div data-role="header"><h1>Page 1</h1></div>
<div data-role="content">
<a href="page2.aspx" data-role="button">Page 2</a></div>
</div>
</div>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<link rel="stylesheet" href="/app.css" />
<script src="/resources/scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="/resources/scripts/jquery.mobile-1.0.1.min.js" type="text/javascript">
</script>
</head>
<body>
<form method="post" action="page2.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNDMyNDU0NjAzZGS9YWabTaXXRTn8y1t/9nyD4FvN9HRt1cI9c8W8lj21mw==" />
</div>
<div id="A" data-role="page">
<div data-role="header"><h1>Page 2 - A</h1></div>
<div data-role="content">
<a href="#B " data-role="button">B</a></div>
</div>
</div>
<div id="B" data-role="page">
<div data-role="header"><h1>Page 2 - B</h1></div>
<div data-role="content">
I can't get to this page!
</div>
</div>
</form>
</body>
</html>
我这样做是有原因的,我在这里提供的示例只是为了演示这个问题。问题是当我从第1页转到第2-A页时,一切都正常。但是,当我单击“B”时“在第2-A页,屏幕将不会导航到该页。但是,这里是它变得奇怪的地方。如果我在浏览器中直接导航到page2.aspx,我可以毫无问题地导航到第2-B页。只有当我从page1.aspx开始时,问题才会发生。有人能帮我一下吗?我的页面代码如下所示:
page1.aspx
Page 1
Page 2 - A
Page 2 - B
<!DOCTYPE html>
<html>
<head><title></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<link rel="stylesheet" href="/app.css" />
<script src="/resources/scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="/resources/scripts/jquery.mobile-1.0.1.min.js" type="text/javascript"> </script>
</head>
<body>
<form method="post" action="page1.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNDMyNDU0NjAzZGRwU4yeA9j5ta11sndZ5ttoGphlk//bQegtegJWNYp1Rg==" />
</div>
<div data-role="page">
<div data-role="header"><h1>Page 1</h1></div>
<div data-role="content">
<a href="page2.aspx" data-role="button">Page 2</a></div>
</div>
</div>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<link rel="stylesheet" href="/app.css" />
<script src="/resources/scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="/resources/scripts/jquery.mobile-1.0.1.min.js" type="text/javascript">
</script>
</head>
<body>
<form method="post" action="page2.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNDMyNDU0NjAzZGS9YWabTaXXRTn8y1t/9nyD4FvN9HRt1cI9c8W8lj21mw==" />
</div>
<div id="A" data-role="page">
<div data-role="header"><h1>Page 2 - A</h1></div>
<div data-role="content">
<a href="#B " data-role="button">B</a></div>
</div>
</div>
<div id="B" data-role="page">
<div data-role="header"><h1>Page 2 - B</h1></div>
<div data-role="content">
I can't get to this page!
</div>
</div>
</form>
</body>
</html>
第1页
page2.aspx
Page 1
Page 2 - A
Page 2 - B
<!DOCTYPE html>
<html>
<head><title></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<link rel="stylesheet" href="/app.css" />
<script src="/resources/scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="/resources/scripts/jquery.mobile-1.0.1.min.js" type="text/javascript"> </script>
</head>
<body>
<form method="post" action="page1.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNDMyNDU0NjAzZGRwU4yeA9j5ta11sndZ5ttoGphlk//bQegtegJWNYp1Rg==" />
</div>
<div data-role="page">
<div data-role="header"><h1>Page 1</h1></div>
<div data-role="content">
<a href="page2.aspx" data-role="button">Page 2</a></div>
</div>
</div>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<link rel="stylesheet" href="/app.css" />
<script src="/resources/scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="/resources/scripts/jquery.mobile-1.0.1.min.js" type="text/javascript">
</script>
</head>
<body>
<form method="post" action="page2.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNDMyNDU0NjAzZGS9YWabTaXXRTn8y1t/9nyD4FvN9HRt1cI9c8W8lj21mw==" />
</div>
<div id="A" data-role="page">
<div data-role="header"><h1>Page 2 - A</h1></div>
<div data-role="content">
<a href="#B " data-role="button">B</a></div>
</div>
</div>
<div id="B" data-role="page">
<div data-role="header"><h1>Page 2 - B</h1></div>
<div data-role="content">
I can't get to this page!
</div>
</div>
</form>
</body>
</html>
第2-A页
第2-B页
我到不了这一页了!
我认为(但没有尝试过)您需要先使用$.mobile.loadPage('testpage.html')
将页面加载到DOM中,然后使用$.mobile.changePage('#bar')
进行转换
更多信息请参见:
$.mobile.changePage()
(index.html#foo)
,
因为框架将查找ID为#foo
而不是用它滚动到内容的本机行为
身份证
好吧,这听起来有点奇怪。但是我尝试了你的例子(通过复制你的代码样本),并且遇到了与你相同的问题。但是,我注意到,您的页面
#B
链接中有一个空格,如下所示:
<a href="#B " data-role="button">...</a>
当我删除空白时,一切正常。试用一下,告诉我它是否适合您。您需要将外部页面标记为外部页面,即。rel=“external” 这将解决您的问题:
<a href="page2.aspx" rel="external" data-role="button">Page 2</a>
您可以使用target:target=“\u self”
对我来说,这是100%的工作。嗨,科尔特曼,谢谢你的尝试。我试过了,但它对我不起作用:(.我查看了我原来的代码库,href中也没有空格。不过谢谢你的指针!我对你的代码所做的唯一其他更改是使用jQuery Mobile 1.0(而不是1.0.1)和将.aspx改为.html(因为这是我存储示例的方式)-但我不认为这有什么区别。不过我只是在firefox上试过,所以这可能与移动浏览器的工作方式有关。