您的位置:首页 > 其它

解决iframe中fixed失效问题

2016-11-02 15:23 211 查看
代码如下:

aa.html

<html>
<head>
<meta name="" content="" charset="utf-8"/>
<script src="js/jquery.min.js"></script>
<script type="text/javascript">

function say() {
    var box = "<div style='width:500px;height:500px;background:red;position:fixed;top:100px;left:100px;'></div>"
    $("body").append(box);
}
//调用bb页面中的创建button方法
function callChild(){
    myFrame.window.say();
}

</script>
</head>
<body>
    <input type=button value="aa页面调用bb" onclick="callChild()">
    <iframe name="myFrame" src="bb.html"></iframe>
    <div style="height:3000px;"></div>
</body>
</html>
bb.html

<html>
<head>
<script src="js/jquery.min.js"></script>
<script type="text/javascript">

function say(){
    $("body").append("<button>按钮</button>");
}
//调用aa页面中的创建box方法
function callParent(){
    parent.say();
}

</script>
</head>
<body>
<input type=button value="bb页面调用aa" onclick="callParent()">
</body>
</html>


其中,页面中使用的jquery需自行加载。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: