新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > Web开发 > JavaScript > 正文:JavaScript学习笔记 3-框架

JavaScript学习笔记 3-框架

新客网 XKER.COM 2008-10-07 来源: 收藏本文
先回顾在html中是如何使用框架的:
Code
<html>
<frameset cols="66%,34%">
<frame src="chicken.html" name="chicken">
<frameset rows="100,*">
<frame src="pastasalad.html" name="pastasalad">
<frame src="jellocubes.html" name="jellocubes">
</frameset>
</frameset>
</html>现在就来看在框架中运用JavaScript的例子:
Code
<html>
<frameset rows="25%,*">
<frame src="frames_example_controls.html" name="control_fram" >
<frame src="blank.html" name="target_frame" >
</frameset>
</html>里面有两个页面,一个是frames_example_controls.html,一个是blank.html:
frames_example_controls.html
<html>
</head>
<body>
<a href="#" onClick="top.target_frame.document.writeln('Monkey do!<br>');">Monkey see</a>
</body>
</html>
top.target_frame.document.writeln("Monkey do!")这句中的 top 是系统内置的变量,翻译的不好,还是看原文:This will always refer to the top-most browser window. If you want to start at the top of the window hierarchy, use top.


最后是一个练习,它涉及到前面学到的内容。

答案如下:


frame代码
<html>
<head>
<title>day_3_homework</title>
</head>
<frameset rows="40%,*" frameborder="1px" border="1px" scrolling="no">
<frame src="day_3_homework_control.html" name="control_frame">
<frame src="day_3_homework_default.html" name="show_frame">
</frameset>
</html>
这个没什么可说的,里而有一点,就是怎么取消框架分隔线

上面的frame取名为control_frame,其代码是:


Code
<html>
<head>
<title>day_3_homework_control</title>
</head>

<body>
<a href="day_3_homework_default.html" target="show_frame"><img src="image/home.gif"></a>
<a href="#"onClick="parent.show_frame.document.bgColor='#00FF00';"><imgsrc="image/green.gif"></a>
<a href="#" onClick="parent.show_frame.document.bgColor='yellow';"><img src="image/yellow.gif"></a>
<a href="day_3_homework_brandme.html" target="show_frame"><img src="image/monkey.gif" name="brandme_img"></a>
</body>

</html>
这段代码里有两个学习点:

下面的frame的内容将有两个页面载入,通过点分别点击control_frame内的两个小图,而显示,其代码分别为:


show_frame内的两个页面的代码
默认页面的代码是:
<html>
<head>
<title>day_3_homework_default</title>
</head>
<body>
<h1>Your Homework Assignment</h1>
<p>Make this page work. If you click on the monkey in the right corner of the page, you'll go to the branding
page from last lesson's homework. If you hit the Home button, you'll come back here. The yellow and green
buttons change the background color of this page.<br><br>
Get these buttons to work, and then View Source to see what I did. </p>
</body>
</html>

-----------------
另一页面的代码是:
<html>
<head>
<title>day_3_homework_brandme</title>
<script language="javascript">
<!--
var image1="image/monkey.gif";
var image2="image/thau.gif";
var image3="image/sun.gif";
-->
</script>
</head>

<body>
<h1>Browser Configuration</h1>
<p>Brand your browser by moving your mouse over the image below until you find one you like. Then click on
the image.</p>
<a href="#" onMouseOver="temp=image1;image1=image2;image2=image3;image3=temp;
window.document.the_image.src=image1;"
onclick="parent.control_frame.document.brandme_img.src=image1;">
<img src="image/monkey.gif" name="the_image" border="0"></a>
</body>
</html>
上面的代码里有很多学习点,值得认真琢磨.
收藏】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
【重要声明】:新客网刊载此文仅为提供更多信息的目的,并不代表新客网同意文章的说法或描述,也不构成任何建议,对本文有任何异议,请在上面提出建议。
  • 阅读排行
  • 推荐阅读
  • 随机推荐