javascript getElementById 样式颜色不适用于非 Web 调色板颜色

发布于 2024-12-02 11:41:59 字数 508 浏览 4 评论 0原文

我需要在页面上显示电子邮件地址,并且我有一个函数可以从垃圾邮件机器人希望无法识别的块中构建电子邮件地址(这部分工作正常)。一旦 javascript 函数连接所有块,我就会使用innerHTML 用电子邮件地址填充一个跨度。

我正在尝试在将链接文本填充到跨度中后对其文本进行着色。这两个都有效:

document.getElementById('span_ID').style.color = 'red';

document.getElementById('span_ID').style.color = '#FF0000';

...但这不是:

document.getElementById('span_ID').style.color = '#2200c1';

它是红色,是网站风格和风格的一部分。无法更改,并且使用默认的蓝色链接也不是一个选项。我已经发现其他一些人问了同样的问题,但他们的解决方案对我不起作用。我还尝试放入连接字符串的函数,但这也不起作用。

那么这是怎么回事?

I need to display an e-mail address on a page, and I have a function that builds an e-mail address from chunks that spambots hopefully won't recognize (this part works fine). I use innerHTML to populate a span with the e-mail address once the javascript function concatenates all of the chunks.

I'm trying to color the text of the link after it has been populated into the span. Both of these work:

document.getElementById('span_ID').style.color = 'red';

document.getElementById('span_ID').style.color = '#FF0000';

...but this doesn't:

document.getElementById('span_ID').style.color = '#2200c1';

It's a red color that's part of the site style & can't be changed, and using the default blue for the link is not an option either. I already found a few other people asking the same question, but their solutions didn't work for me. I also tried putting in the function that concatenates the string, which also didn't work.

So what's up here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

中性美 2024-12-09 11:41:59

不确定这是否会产生影响,但您是否尝试过将“#2200c1”中的 c 大写?我认为这不是问题,但你不妨尝试一下!

Not sure if this will make a difference but have you tried capitalising the c in '#2200c1'? I don't think that would be a problem but you might as well try!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文