问题
listening to pagebeforechange event...
$(document).bind("pagebeforechange", function ( event , data) {
//event is triggered from an anchor tag... //Is it possible to get reference to anchor( or event.srcElement) here
});
or .....
A simple sample below if somebody want to try it out...
<head>
<title>Main menu</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"
/>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
$(document).bind("pagebeforechange", function (event, data) {
if (typeof data.toPage === "string") {
//event is triggered from an anchor tag...
//Is it possible to get reference to anchor( or event.srcElement) here
event.preventDefault();
}
});
</script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
</head>
<body>
<div data-role="page" id="home">
<div data-role="header" data-theme="a"></div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<li>
<a href="#category-items?category=animals">Animals</a>
</li>
</ul>
</div>
</div>
</body>
</html>
回答1:
How about event.liveFired.activeElement;
来源:https://stackoverflow.com/questions/9179096/jqm-pagebeforechange-and-event-source