jquery mobile跳转到指定id时怎样传递参数

在jquery mobile 中,每一个页面都是一个page,当我们需要从一个页面跳转到另一个页面时,可以在href中指定id,可是该怎么把一个page中的参数传递到另外一个page中,几经琢磨,发现可以通过点击函数的参数来传递值,代码如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<link href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js" type="text/javascript"></script>
</head>

<body>
<script>
function goto_other_page(username){
    $("#page2_username").text(username);
    };
</script>
<div data-role="page" id="page1">
  <div data-role="header">
    <h1>标题</h1>
  </div>
  <div data-role="content">
    <ul data-role="listview">
    <!--函数中的参数可以根据需要,通过拼接的方式动态添加-->
      <li><a href="#page2" onClick="goto_other_page('张三');">页面</a></li>
    </ul>



  </div>
  <div data-role="footer" data-position="fixed">
    <h4>脚注</h4>
  </div>
</div>
<div data-role="page" id="page2">
  <div data-role="header">
    <h1>标题</h1>
  </div>
  <div data-role="content">
    <label id="page2_username"></label>
  </div>
  <div data-role="footer" data-position="fixed">
    <h4>脚注</h4>
  </div>
</div>

</body>
</html>
原文地址:https://www.cnblogs.com/qitian1/p/6461879.html