您的位置:首页 > Web前端 > JavaScript

实现 iframe 子页面调用父页面中的js方法

2013-11-04 10:54 369 查看
父页面:index.html(使用iframe包含子页面child.html)
[xhtml] view plaincopyprint?

<html>

<head>

<script type="text/javascript">

<!--

function toshow(msg){

alert("这里是父页面:"+msg);

}

// -->

</script>

</head>

<body>

<iframe background="blue" src="child.html" mce_src="child.html"></iframe>

</body>

</html>

子页面child.html(调用父页面toshow方法)

[xhtml] view plaincopyprint?

<html>

<head>

<script type="text/javascript">

<!--

function doparent(){

window.parent.toshow('ccccchild');

}

// -->

</script>

</head>

<body>

This is child frame!!

<input type="button" value="请点击" onclick='doparent()'></input>

</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: