记录在当前页面引入另一个页面的方式,包含如何传参数
一、iframe嵌套页面传值
页面1传递参数
<body>
<div>页面一</div>
<iframe id="frameqy" src="a.html" width="100%" height="520px" frameborder="0" scrolling="0"></iframe>
<script>
//通过src向子元素传递参数
let url = document.getElementById('frameqy').src + '?param='+参数值
document.getElementById('frameqy').src = url;
</script>
</body>
页面2接收参数
var aaa= GetQueryString("param") ;//和页面一传递的参数名称一致
alert(aaa);//接收到的参数
function GetQueryString(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null){
return unescape(r[2]);
}
return null;
}
二、html link引入页面
页面1用link引入a.html页面,定义一个id
<head>
<link rel="import" href="a.html" id="aaId">
</head>
<body>
<div id="bbId"></div>
<script>
$(document).ready(function(){
$("#bbId").load(aaId.href);//onload的时加载页面,将a.html渲染到div中
})
// window.onload = function(){
// $("#bbId").load(aaId.href);//onload的时加载页面,将a.html渲染到div中
// }
</script>
</body>