js父页面中使用子页面的方法
作者:bea
iframe是非常常用的一个html元素,如果在父页面中使用子页面的方法应该怎么写呢,下面就做一下简单的介绍。 一、父页面代码 <html><head><meta charset=" gb2312"><title>父页面</title><script type="text/javascript">function parentFunction() { alert('function in paren
iframe是非常常用的一个html元素,如果在父页面中使用子页面的方法应该怎么写呢,下面就做一下简单的介绍。 一、父页面代码
<html>
<head>
<meta charset=" gb2312">
<title>父页面</title>
<script type="text/javascript">
function parentFunction()
{
alert('function in parent');
}
function callChild()
{
child.window.childFunction();
/*
child 为iframe的name属性值,
不能为id,因为在FireFox下id不能获取iframe对象
*/
}
</script>
</head>
<body>
<iframe name="child" src="./child.html" ></iframe>
</body>
</html>
二、iframe中的代码
<html>
<head>
<meta charset="gb2312">
<title>iframe代码</title>
<script type="text/javascript">
function childFunction()
{
alert('function in child');
}
function callParent()
{
parent.parentFunction();
}
</script>
</head>
<body>
</body>
</html>
上面两个代码可以在父页面和子页面对对方的函数进行相互调用,比较简单,不多介绍了。 希望本文所述对大家学习javascript程序设计有所帮助。
有用 | 无用
<html>
<head>
<meta charset=" gb2312">
<title>父页面</title>
<script type="text/javascript">
function parentFunction()
{
alert('function in parent');
}
function callChild()
{
child.window.childFunction();
/*
child 为iframe的name属性值,
不能为id,因为在FireFox下id不能获取iframe对象
*/
}
</script>
</head>
<body>
<iframe name="child" src="./child.html" ></iframe>
</body>
</html>
二、iframe中的代码
<html>
<head>
<meta charset="gb2312">
<title>iframe代码</title>
<script type="text/javascript">
function childFunction()
{
alert('function in child');
}
function callParent()
{
parent.parentFunction();
}
</script>
</head>
<body>
</body>
</html>
上面两个代码可以在父页面和子页面对对方的函数进行相互调用,比较简单,不多介绍了。 希望本文所述对大家学习javascript程序设计有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- jquery插件EasyUI中form表单提交实例分享
- 详解WordPress开发中get_current_screen()函数的使用
- 提升jQuery的性能需要做好七件事
- jQuery 移动端artEditor富文本编辑器
- AngularJs动态加载模块和依赖注入详解
- jquery在ie7下选择器的问题导致append失效的解决方法
- 基于Node.js的强大爬虫 能直接发布抓取的文章哦
- JavaScript基础知识及常用方法总结
- jQuery实现的调整表格行tr上下顺序
- javascript实现checkbox复选框实例代码
- 基于javascript实现彩票随机数生成(升级版)
- 分享有关jQuery中animate、slide、fade等动画的连续触发、滞后反复执行的bug
- 理解Angular数据双向绑定
- JavaScript表单验证实例之验证表单项是否为空
- JavaScript电子时钟倒计时第二款
- 基于javascript实现彩票随机数生成(简单版)
- Node.js静态文件服务器改进版
- 实例讲解javascript注册事件处理函数
- 详解javascript事件冒泡