[英]How do I use javascript to change the font colour on my webpage?
I can't use JQuery sadly I need to use good old Javascript. 可悲的是,我不能使用JQuery,我需要使用良好的旧Javascript。
I have a forum and a black theme and when people use black text on it you can't see it. 我有一个论坛和一个黑色主题,当人们在其上使用黑色文字时,您看不到它。 So I want to use javascript to change all the black text on the page to white when the page loads.
因此,我想使用javascript在页面加载时将页面上的所有黑色文本更改为白色。
document.body.style.color = '#555555'
of course then you have to use the getElementById
function instead of body if you want to select a specific element. 当然,如果要选择特定元素,则必须使用
getElementById
函数而不是body。
That's not really smart though. 不过,这并不是很聪明。 Go with CSS.
使用CSS。
Other answerers have posted JavaScript solutions if you really want to use JS for this, so I won't add another. 如果您真的想为此使用JS,其他答复者已经发布了JavaScript解决方案,因此我将不再添加其他解决方案。 However, I just thought I'd offer two alternatives:
但是,我只是想提供两种选择:
If you find that black is the default color for any posts, and you can modify your theme, don't use JavaScript for this — open your theme's CSS file, try to locate the style that makes post text black, and change it to white. 如果您发现黑色是所有帖子的默认颜色,并且您可以修改主题,请不要使用JavaScript-打开主题的CSS文件,尝试找到使帖子文本为黑色的样式,然后将其更改为白色。
If black text is simply caused by people changing the color to be such in their own posts, I think a better idea would be to just tell your members not to use black text. 如果黑色文本仅是由于人们在自己的帖子中将颜色更改为这种颜色而引起的,那么我认为一个更好的主意是只告诉您的成员不要使用黑色文本。 I can also see legitimate uses of black text on black backgrounds, eg for a lack of spoiler tags in your forum software.
我还可以看到在黑色背景上合法使用黑色文本,例如,由于论坛软件中缺少扰流标签。
如果您是想动态更改主题/样式,则可以使用javascript通过通过document.getElementsByTagName(“ link”)选择链接标签来禁用和启用头部的CSS链接元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.