iframe使用方法
2015-12-18 20:05
459 查看
<iframe name="myiframe" src="/i/eg_landscape.jpg"></iframe>
父页面给iframe中的子页面传值,把值写入子页面的文本框里
father.html:
<script language="javascript" src="http://www.aspbc.com/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function fuzhi()
{
$('#son').contents().find("#b").val("父页面传过来的值!");
}
</script>
<iframe id="son" name="son" src="son.html" width="400" height="200"></iframe><br />
<input type="button" value="给子页面表单中id为b的文本框赋值" onclick="fuzhi()" />
son.html:
<form name="form2"><input type="text" name="b" id="b" /></form>
-------------------------------------------------------------------------------------------------------------
iframe中的子页给父页面传值
father.html
<script language="javascript" src="http://www.aspbc.com/js/jquery.js" type="text/javascript"></script>
<div id="messagediv">test</div>
<iframe id="son" name="son" src="son.html" width="400" height="200">
</iframe>
son.html
<script type="text/javascript">
function fuzhi()
{
$(window.parent.$("#messagediv").html("子页面赋过来的值"));
}
</script>
<form name="form2"><input name="btn1" type="button" onclick="fuzhi()" value="给父页中id为messagediv的元素赋值" /></form>
-----------------------------------------------------------------------------------------------------------------------------------------
子页面如何调用父页面中的函数
father.html
<script language="javascript" src="http://www.aspbc.com/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function fun()
{
alert('这是父页面中的函数弹出窗口哦!');
}
</script>
<iframe id="son" name="son" src="son.html" width="400" height="200"></iframe>
son.html
<script type="text/javascript">
function diaoyong()
{
$(window.parent.fun()); //调用父页面函数
}
</script>
<form name="form2"> <input name="btn1" type="button" onclick="diaoyong()" value="调用父页面中的函数" /></form>
----------------------------------------------------------------------------------------------------------------------------
父窗口调用iframe子窗口方法
1、HTML语法:<iframe name="myFrame" src="child.html"></iframe>
2、父窗口调用子窗口:myFrame.window.functionName();
3、子窗品调用父窗口:parent.functionName();
简单地说,也就是在子窗口中调用的变量或函数前加个parent.就行
4、父窗口页面源码:
复制代码 代码如下:
<html>
<head>
<script type="text/javascript">
function say() {
alert("parent.html------>I'm at parent.html");
}
function callChild()
{
//document.frames("myFrame").f1();
myFrame.window.say();
}
</script>
</head>
<body>
<input type=button value="调用child.html中的函数say()" onclick="callChild()">
<iframe name="myFrame" src="child.html"></iframe>
</body>
</html>
5、子窗口页面:
复制代码 代码如下:
<html>
<head>
<script type="text/javascript">
function say()
{
alert("child.html--->I'm at child.html");
}
function callParent() {
parent.say();
}
</script>
</head>
<body>
<input type=button value="调用parent.html中的say()函数" onclick="callParent()">
</body>
</html>
父页面给iframe中的子页面传值,把值写入子页面的文本框里
father.html:
<script language="javascript" src="http://www.aspbc.com/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function fuzhi()
{
$('#son').contents().find("#b").val("父页面传过来的值!");
}
</script>
<iframe id="son" name="son" src="son.html" width="400" height="200"></iframe><br />
<input type="button" value="给子页面表单中id为b的文本框赋值" onclick="fuzhi()" />
son.html:
<form name="form2"><input type="text" name="b" id="b" /></form>
-------------------------------------------------------------------------------------------------------------
iframe中的子页给父页面传值
father.html
<script language="javascript" src="http://www.aspbc.com/js/jquery.js" type="text/javascript"></script>
<div id="messagediv">test</div>
<iframe id="son" name="son" src="son.html" width="400" height="200">
</iframe>
son.html
<script type="text/javascript">
function fuzhi()
{
$(window.parent.$("#messagediv").html("子页面赋过来的值"));
}
</script>
<form name="form2"><input name="btn1" type="button" onclick="fuzhi()" value="给父页中id为messagediv的元素赋值" /></form>
-----------------------------------------------------------------------------------------------------------------------------------------
子页面如何调用父页面中的函数
father.html
<script language="javascript" src="http://www.aspbc.com/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function fun()
{
alert('这是父页面中的函数弹出窗口哦!');
}
</script>
<iframe id="son" name="son" src="son.html" width="400" height="200"></iframe>
son.html
<script type="text/javascript">
function diaoyong()
{
$(window.parent.fun()); //调用父页面函数
}
</script>
<form name="form2"> <input name="btn1" type="button" onclick="diaoyong()" value="调用父页面中的函数" /></form>
----------------------------------------------------------------------------------------------------------------------------
父窗口调用iframe子窗口方法
1、HTML语法:<iframe name="myFrame" src="child.html"></iframe>
2、父窗口调用子窗口:myFrame.window.functionName();
3、子窗品调用父窗口:parent.functionName();
简单地说,也就是在子窗口中调用的变量或函数前加个parent.就行
4、父窗口页面源码:
复制代码 代码如下:
<html>
<head>
<script type="text/javascript">
function say() {
alert("parent.html------>I'm at parent.html");
}
function callChild()
{
//document.frames("myFrame").f1();
myFrame.window.say();
}
</script>
</head>
<body>
<input type=button value="调用child.html中的函数say()" onclick="callChild()">
<iframe name="myFrame" src="child.html"></iframe>
</body>
</html>
5、子窗口页面:
复制代码 代码如下:
<html>
<head>
<script type="text/javascript">
function say()
{
alert("child.html--->I'm at child.html");
}
function callParent() {
parent.say();
}
</script>
</head>
<body>
<input type=button value="调用parent.html中的say()函数" onclick="callParent()">
</body>
</html>
相关文章推荐
- 最近5年133个Java面试问题列表
- jade模板
- uva 10559——Blocks
- C++中的字节对齐分析
- Android 开源项目分类汇总
- checkbox组件
- hdoj 采矿 1173 (数学中位数)
- beaglebonedemo嵌入式简单设备驱动实验心得
- Hadoop谁在用?
- cocos2d-x 2.x版本接入bugly的总结
- 2015年终工作总结
- Sicily Connect components in undirected graph
- 分布式系统的本质:拆分+连接
- 分布式系统的本质:拆分+连接
- 05-2 界面跳转+屏幕旋转(图片旋转/弹框判断)
- win10+VS2013编译caffe的common.cpp错误error C4996: ‘getpid': The POSIX name for this item is deprecated.
- 分布式系统的本质:拆分+连接
- [Nginx][HttpUpstreamModule]翻译负载均衡
- 简单的计算机二维数组的元素和
- 循环遍历数组方法