五分钟内反应回复,平均十分钟解决任何IT技术问题,按难度跟工作量收费!

控制框架内部内容跟框架内部控制外部的JS代码

admin |浏览446次
检举|收藏|2017/06/15 14:27

案例一:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>框架控制</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript">document.domain = '127.0.0.1:81';</script><!--网址,不带http:// 必须要这句,不然没用哦-->
</head>
<body>
<div id="login" style="display:none;"><a href="javascript:;" onclick="$(window.frames['iframe1'].document).find('#h').css('display','none');">点击</a></div>
<iframe src="b.html" id="iframe1" name="iframe1" width="500" height="50"></iframe>
</body>
</html>


案例二:


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>框架控制</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript">document.domain = '127.0.0.1:81';</script><!--网址,不带http:// 必须要这句,不然没用哦-->
</head>
<body>
<a href="javascript:;" onclick="$('#login',window.parent.document).css('display','block');">点击</a>
<a href="javascript:;" onclick="window.top.location.reload();">刷新</a>
<div id="h" style="display:block;">这里要被隐藏</div>
</body>
</html>


案例三:(在框架内调用框架外的方法)


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>框架控制</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript">document.domain = '127.0.0.1:81';</script><!--网址,不带http:// 必须要这句,不然没用哦-->


<script>

function akui()
{
alert("ddd");
}

</script>

</head>
<body>
<div id="login" ><a href="javascript:;" onclick="$(window.frames['iframe1'].document).find('#h').css('color','red');">点击</a></div>
<iframe src="b.html" id="iframe1" name="iframe1" width="500" height="50"></iframe>
</body>
</html>


案例四:(在框架内调用框架外的方法)


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>框架控制</title>

<script type="text/javascript">document.domain = '127.0.0.1:81';</script><!--网址,不带http:// 必须要这句,不然没用哦-->
</head>
<body>
<a href="javascript:;" onclick="parent.window.akui();">点击</a>
<a href="javascript:;" onclick="window.top.location.reload();">刷新</a>
<div id="h" style="display:block;">这里要被隐藏</div>
</body>
</html>

全部回答(0)
 加载中...