我试图在jquerymobile.js中创建页面时在同一个html页面中传递一个get变量 html包含下面提供的各种内部页面。现在我想将变量传递到同一个html中的其他页面,如id ='page1',id ='page2'等。任何人都可以帮助我如何在同一个html中传递get或post变量? decodeURI(getUrlVars()[“type”])在这种情况下不起作用,因为使用id over page(id ='page2')传递数据 这是代码:
//Page 1 within the same HTML
<div data-role="page" id="page1">
<div data-role="header" data-theme="b">
<h1>Page1 Header</h1>
</div>
<div data-role="content">
//dynamic server content displayed here
</div>
<div data-role="footer" data-position="fixed" data-theme="b">
</div>
</div>
//Page 2 within the same HTML
<div data-role="page" id="page2">
<div data-role="header" data-theme="b">
<h1>Page2 Header</h1>
</div>
<div data-role="content">
//Want to get some of the individual dynamic content displayed in page1 using get method in JSON
</div>
<div data-role="footer" data-position="fixed" data-theme="b">
</div>
I am trying to pass get variable as <a href="#page2?id=$id">Button</a> which is not working.
答案 0 :(得分:0)
使用以下函数获取参数值
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}