在JavaScript中将背景颜色设置为变量 [英] Setting background color to variable in javascript

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

问题描述

好吧,所以我是Java语言的新手,我想知道如何将背景色设置为变量.具体来说,我有三个不同的框架,我希望侧面的两个框架可以根据在第三框架中访问哪个页面来更改其颜色.如何将这两个侧面框架的背景色设置为一个可以由第三框架中的任何文档更改的变量?我一直在网上闲逛,但搜索一直没有结果.

Ok, so I'm very new to Javascript and I was wondering how one goes about making the background color a variable. Specifically, I have three different frames, and I want two of the ones on the side to change their color based on which page is being visited in the third frame. How can I set the background color to for these two side frames to a variable that can be changed by whatever document is in the third frame? I've been looking around online but my search has been fruitless.

编辑- 另外,通过单击超链接来更改它的方法也可以达到我的目的.

EDIT- Alternately, a way to change it by clicking on a hyperlink would work just as well for my purposes.

编辑2- 与最后一个问题相同,这是我正在尝试的一种替代方法,虽然也有更多信息,但它也不会带来太多运气: 在javascript第2部分中将背景颜色设置为变量

EDIT 2 - In the same vein as the last question, this is an alternate approach I'm trying that isn't producing much luck either, though I have more information about it: Setting background color to variable in javascript Part 2

推荐答案

要使用javascript处理背景颜色属性,您需要:

To manipulate the background color property with javascript you need to:

//Set to red
document.getElementById("frame").style.backgroundColor="red"; 

//Save into variable
var color = document.getElementById("frame").style.backgroundColor; 

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

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