JQueryiframe页面操作父页面中的元素与方法(实例讲解) - Web前端
作者:98wpeu发布时间:2026-06-09分类:网页前端技术浏览:3
1)在iframe中查找父页面元素的方法:
$('#id', window.parent.document)
2)在iframe中调用父页面中定义的方法和变量:
parent.method
parent.value
3)实例
1.父页面
复制代码 代码如下:
<%@ Page Language="c#" AutoeventWireup="true" codeBehind="Default.aspx.cs" Inherits="IframeDemo._Default" %>
<!DOCtypehtml PUBLIC "-//W3C//DTD xhtml 1.0 Transitional//EN" "http://www.w3.org/TR/xHTML1/DTD/xhtml1-transitional.dtd">
<html xmlns="HTTP://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script language="javascript" type="text/JavaScript" src="JQuery-1.5.1.min.JS"></script>
<script language="Javascript" type="text/javascript">
var hello = 'hello';
functiongetHelloWorld() {
alert('hello world');
}
</script>
</head>
<body>
<FORM id="form1" runat="server">
<div>
<div id="default" style=" width:200px; height:400px; float:left;">default.aspx</div>
<iframe id="iframeid" src="IFrame.aspx" style=" width:400px; height:400px; float:left;"></iframe>
</div>
</Form>
</body>
</html>
2.子页面
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IFrame.aspx.cs" Inherits="IframeDemo.IFrame" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script language="javascript" type="text/Javascript" src="jQuery-1.5.1.min.js"></script>
<script language="javascript" type="text/javascript">
$(function() {
//在iframe中查找父页面元素
alert($('#default', window.parent.document).html());
//在iframe中调用父页面中定义的方法
parent.getHelloWorld();
//在iframe中调用父页面中定义的变量
alert(parent.hello);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="iframe">
IFrame.aspx
</div>
</form>
</body>
</html>
相关推荐
- jQuery实现鼠标移到元素上动态提示消息框效果 - Web前端
- 基于jquery的网站幻灯片切换效果焦点图代码 - Web前端
- jQuery读取和设定KindEditor值的方法 - Web前端
- jquery实现兼容浏览器的图片上传本地预览功能 - Web前端
- jquery 跳到顶部和底部动画2句代码简单实现 - Web前端
- jQuery 顶部导航跟随滚动条滚动固定浮动在顶部 - Web前端
- 多个datatable共存造成多个表格的checkbox都被选中 - Web前端
- jQuery Animation实现CSS3动画示例介绍 - Web前端
- 实用的Jquery选项卡TAB示例代码 - Web前端
- jquery实现漂浮在网页右侧的qq在线客服插件示例 - Web前端
- 网页前端技术排行
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


