使用javascript,我希望能够获取随机动态变化的字体颜色

With javascript i want to be able to grab the font color which is dynamically changing randomly

本文关键字:变化 动态 字体 颜色 随机 获取 javascript 我希望 使用      更新时间:2023-09-26

我想获取字体颜色例如

#FF0000

或者可能是

#568000    etc..

我的表

<table class="mytable">
   <th class=vertical bgcolor=#C0C0C0 align=center> <font color=#FF0000 size=2> Test this out</font>
  </th>
  <th class=vertical bgcolor=#C0C0C0 align=center> <font color=#568000 size=2> Test this out</font>
  </th>
</table>

看起来像是正常的css属性,我可以得到一些

newInnerDiv.css("background-color");

但这是TABLE TH元素内部的字体标记颜色。我怎样才能达到那种字体颜色?我似乎兄弟元素将获得下一个TH等…

Fiddle

http://jsfiddle.net/y8ct6b5u/6/

这很有效。。。请在你的控制台上试试。

js: document.querySelector('font').color
output:    "#FF0000"

试试看:这是为您的表头获取颜色。。。

<script type="text/javascript">

        $(document).ready(function () {
        $("font").each(function () {
          var getcolor= $(this).attr("color");
        });
    });
    </script>