javascript - 通过javascript代码更改html中的文本颜色

标签 javascript html colors

我正在尝试更改标题颜色,因为我在下面的 html 代码中编写了该颜色以及颜色的颜色 文本的内容不会改变。 我该如何更改它?

 /**
     * Build a HTML table with the data
     */
    Highcharts.Chart.prototype.getTable = function () {
        var title =this.title.text; 
        var device = this.series[0].name;
        var unit = this.series[0].yAxis.axisTitle.text;

       // var html = '<table>',
        var html = '<h1 style="color:red">'+title+'</h1> <h2 style="color:red" >Device: '+device+'</h2><h2 style="color:red" >Unit: '+unit+'</h2>'+
        '<table>',
            rows = this.getDataRows();
        html += '</table>';
        return html;
    };

谢谢,米哈尔

最佳答案

使用以下代码而不是在 JavaScript 中编写 HTML 代码:

document.getElementById("Your_element_Id").style.color="Any_color";

关于javascript - 通过javascript代码更改html中的文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27688500/

相关文章:

javascript - angularjs 对话框似乎对我不起作用

html - 允许图像覆盖屏幕上所有内容的 CSS 动画

HTML5 Canvas - 绘制

colors - 背景颜色, Notepad++ ,用于突出显示

php - 更新 JS Var 更改 php var

javascript - D3 - 让 child 填充 parent 组

javascript - 使用动态模式从 JSON 加载

javascript - 在路径中绘制不同颜色的形状(HTML5 Canvas/Javascript)

android - 在 ListView 中使用 RelativeLayout 时 View 的背景颜色被移除

css - 向 WooCommerce 下拉菜单添加样式?