在javascript第2部分中将背景颜色设置为变量 [英] Setting background color to variable in javascript Part 2

查看:106
本文介绍了在javascript第2部分中将背景颜色设置为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JavaScript还是很陌生,我有一个网页,其中包含3个嵌套框架(一个顶部框架,然后一个底部框架分成两部分.)顶部框架的标题为Head,左下方的标题为LeftFrame.最后一个标题为RightFrame.现在,LeftFrame是一个导航栏,我要创建它,以便单击LeftFrame中的链接将更改Head的背景颜色. 这是主页的代码:

I'm very new to JavaScript, and I have a webpage with 3 nested frames (a top one, and then a bottom one divided into two.) The top frame is titled Head, the bottom-left one is titled LeftFrame and the final one is titled RightFrame. Now, LeftFrame is a navigation bar, and I want to make it so that clicking on a link in LeftFrame will change the background color of Head. This is the code for the main webpage:

<HTML>
<HEAD>
<TITLE>Webcomics Review</TITLE>
</HEAD>

<FRAMESET BORDER=0 ROWS="12%,*">
<FRAME NAME"Head" NORESIZE SRC="Head.html">

<FRAMESET BORDER=0 COLS="15%,*">
<FRAME NAME="LeftFrame" NORESIZE SRC="navigation.html">
<FRAME NAME="RightFrame" NORESIZE SRC="mainpage.html">
</FRAMESET>

</FRAMESET>
</HTML>

这是导航栏的代码,到目前为止,只有一个链接正在测试:

And this is the code for the navigation bar which just has one link being worked on so far as a test:

<HTML>
<HEAD>
<TITLE>Webcomics Review</TITLE>
<SCRIPT>
function setColor1(number)
{
    if (number==1)
    {
        parent.Head.document.body.style.backgroundColor=#FF0000;
    }
    return;
}
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<FONT SIZE=3 FACE=Haettenschweiler>Webcomics:
<BR><BR>
<A HREF="xkcd.html" TARGET="RightFrame" STYLE="text-decoration: none" onClick="setColor1(1)">Xkcd</A>
<BR><BR>
<A HREF="qc.html" TARGET="RightFrame" STYLE="text-decoration: none">Questionable Content</A>
<BR><BR>
<A HREF="qwantz.html" TARGET="RightFrame" STYLE="text-decoration: none">Dinosaur Comics</A>
<BR><BR>
<A HREF="survivingtheworld.html" TARGET="RightFrame" STYLE="text-decoration: none">Surviving the World</A>
<BR><BR>
</CENTER>
</BODY>
</HTML>

有人可以让我知道我在做什么,因为单击导航中的"xkcd"链接(我正在测试的那个链接)时,头部框架没有任何变化.

Could someone let me know what I'm doing wrong, as nothing about the Head frame changes when upon clicking the "xkcd" link in navigation (the one I'm using to test.)

推荐答案

尝试一下:

//MAIN FRAMES PAGE
<html>
<head>
<title>test</title>
<script type="text/javascript">
function setColor1(color)
{
    HEAD.document.body.style.backgroundColor=color;
    return;
}
window.setColor = function(a){setColor1(a);}
</script>
</head>
<FRAMESET BORDER=1 ROWS="12%,*">
<FRAME NAME="HEAD" NORESIZE SRC="frame_head.html" id="HEAD">
<FRAMESET BORDER=1 COLS="15%,*">
    <FRAME NAME="LeftFrame" NORESIZE SRC="frame_footer.html">
    <FRAME NAME="RightFrame" NORESIZE SRC="frame_body.html">
</FRAMESET>
</FRAMESET>
</html>
//END MAIN FRAMES PAGE
/**************************************************************************/
//BODY PAGE (RightFrame)
<html>
<head>
<title>test</title>
<script type="text/javascript">
function setColor(color)
{
    window.parent.setColor(color);
    return;
}
</script>
</head>
<body>
    <a href="#" onclick="setColor('#f00')">one</a>&nbsp;
    <a href="#" onclick="setColor('#0f0')">two</a>&nbsp;
    <a href="#" onclick="setColor('#00f')">three</a>&nbsp;
    <a href="#" onclick="setColor('#f0f')">four</a>&nbsp;
    <a href="#" onclick="setColor('#ff0')">five</a>&nbsp;
    <a href="#" onclick="setColor('#0ff')">six</a>&nbsp;
</body>
</html>
/**************************************************************************/

这篇关于在javascript第2部分中将背景颜色设置为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆