面板不改变页面在jquery移动



我正在尝试编写一个面板,在用户点击链接后关闭并更改当前页面,但链接被点击后没有发生任何事情。

我最初试图用一个标签来改变页面。但无济于事。下面是我的代码:

$("a").on("tap", function(){
    switch($(this).attr("id")) {
		case "#woke":
			$.mobile.changePage("#woke");
			break;
        case "#network": 
			$.mobile.changePage("#network");
			break;
    }
});
<html lang="en">
	<head>
		<title>Organize.me</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link rel="stylesheet" href="main.css" type="text/css"/>
		<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
		<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
		<script src="main.js"></script>
		<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
		
	</head>
	
	<body>					
		<div data-role="page" id="woke">
			<!--Navigation panel with links-->
			<div data-role="panel" data-dismissible="true" data-swipe-close="true" data-display="overlay" data-fixed-position="true" id="menu">
				<div data-role="header">						
						<h1>Menu</h1>	
						<a href="#network" data-rel="close" class="ui-btn ui-btn-right ui-icon-back ui-btn-icon-left">Back</a>
				</div>				
				<nav><ul data-role="listview" data-inset="true">	
					<a href="#woke" class="nav-woke"><li class="buttons">Get Woke</li></a>
					<a href="#network"><li class="buttons">My Network</li></a>
					<a href="#"><li class="buttons">Find Orgs</li></a>
					<a href="#"><li class="buttons">Events</li></a>
					<a href="#"><li class="buttons">Voting</li></a>			
				</ul></nav>
			</div>
			
			<!--Header-->
			<div data-role="header">
				<a href="#menu" data-rel="close" class="ui-btn ui-icon-bars ui-btn-icon-left">Menu</a>
				<h1>Get Woke</h1>
			</div>
			
			<!--Content-->
			<div data-role="content"></div>
			
			<!--Footer-->
			<div data-role="footer">&copy;Scripts of Steele</footer>
		</div>
		
		<div data-role="page" id="network">
			<!--Navigation panel with links-->
			<div data-role="panel" data-dismissible="true" data-swipe-close="true" data-display="overlay" data-fixed-position="true" id="menu">
				<div data-role="header">
						<a href="#network" data-rel="close" class="ui-btn ui-icon-back ui-btn-icon-left">Back</a>
						<h1>Menu</h1>				
				</div>				
				<nav><ul data-role="listview" data-inset="true">	
					<a href="#woke" data-rel="open"><li class="buttons">Get Woke</li></a>
					<a href="#network" data-rel="open"><li class="buttons">My Network</li></a>
					<a href="#"><li class="buttons">Find Orgs</li></a>
					<a href="#"><li class="buttons">Events</li></a>
					<a href="#"><li class="buttons">Voting</li></a>			
				</ul></nav>
			</div>
			
			<!--Header-->
			<div data-role="header">
				<a href="#menu" data-rel="close" class="ui-btn ui-icon-bars ui-btn-icon-left">Menu</a>
				<h1>My Networks</h1>
			</div>
			
			<!--Content-->
			<div data-role="content"></div>
			
			<!--Footer-->
			<div data-role="footer">&copy;Scripts of Steele</footer>
		</div>
		
	</body>
</html>

您正在选择id,但也许您想选择href(或更好,添加id)

$("a").on("tap", function(){
    switch($(this).attr("href")) {
		case "#woke":
            console.log("#woke");
			$.mobile.changePage("#woke");
			break;
        case "#network": 
            console.log("#network");
			$.mobile.changePage("#network");
			break;
    }
});
<html lang="en">
	<head>
		<title>Organize.me</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link rel="stylesheet" href="main.css" type="text/css"/>
		<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
		<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
		<script src="main.js"></script>
		<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
		
	</head>
	
	<body>					
		<div data-role="page" id="woke">
			<!--Navigation panel with links-->
			<div data-role="panel" data-dismissible="true" data-swipe-close="true" data-display="overlay" data-fixed-position="true" id="menu">
				<div data-role="header">						
						<h1>Menu</h1>	
						<a href="#network" data-rel="close" class="ui-btn ui-btn-right ui-icon-back ui-btn-icon-left">Back</a>
				</div>				
				<nav><ul data-role="listview" data-inset="true">	
					<a href="#woke" class="nav-woke"><li class="buttons">Get Woke</li></a>
					<a href="#network"><li class="buttons">My Network</li></a>
					<a href="#"><li class="buttons">Find Orgs</li></a>
					<a href="#"><li class="buttons">Events</li></a>
					<a href="#"><li class="buttons">Voting</li></a>			
				</ul></nav>
			</div>
			
			<!--Header-->
			<div data-role="header">
				<a href="#menu" data-rel="close" class="ui-btn ui-icon-bars ui-btn-icon-left">Menu</a>
				<h1>Get Woke</h1>
			</div>
			
			<!--Content-->
			<div data-role="content"></div>
			
			<!--Footer-->
			<div data-role="footer">&copy;Scripts of Steele</footer>
		</div>
		
		<div data-role="page" id="network">
			<!--Navigation panel with links-->
			<div data-role="panel" data-dismissible="true" data-swipe-close="true" data-display="overlay" data-fixed-position="true" id="menu">
				<div data-role="header">
						<a href="#network" data-rel="close" class="ui-btn ui-icon-back ui-btn-icon-left">Back</a>
						<h1>Menu</h1>				
				</div>				
				<nav><ul data-role="listview" data-inset="true">	
					<a href="#woke" data-rel="open"><li class="buttons">Get Woke</li></a>
					<a href="#network" data-rel="open"><li class="buttons">My Network</li></a>
					<a href="#"><li class="buttons">Find Orgs</li></a>
					<a href="#"><li class="buttons">Events</li></a>
					<a href="#"><li class="buttons">Voting</li></a>			
				</ul></nav>
			</div>
			
			<!--Header-->
			<div data-role="header">
				<a href="#menu" data-rel="close" class="ui-btn ui-icon-bars ui-btn-icon-left">Menu</a>
				<h1>My Networks</h1>
			</div>
			
			<!--Content-->
			<div data-role="content"></div>
			
			<!--Footer-->
			<div data-role="footer">&copy;Scripts of Steele</footer>
		</div>
		
	</body>
</html>

相关内容

  • 没有找到相关文章

最新更新