【问题标题】:how to add CSS for a innerhtml in javascript如何在javascript中为innerhtml添加CSS
【发布时间】:2023-03-27 06:19:02
【问题描述】:

在我的 innerhtml 中,我有通过和失败,我想为这些添加 css 属性。

function display()
{
    var a=document.getElementById("myList");
    var dropdownvalue = a.options [a.selectedIndex].text;
    var b=document.getElementById("myText").value;

    if(dropdownvalue == b.substring(0,4)) {
        document.getElementById("result").innerHTML = "Pass"; 
    } else {
        document.getElementById("result").innerHTML = "Fail";  
    }
}

【问题讨论】:

标签: javascript html css


【解决方案1】:

你可以使用 .style

if(dropdownvalue == b.substring(0,4)) {
        document.getElementById("result").innerHTML = "Pass"; 
        document.getElementById("result").style.color = "green";
     }
        else {
        document.getElementById("result").innerHTML=    "Fail";  
        document.getElementById("result").style.color = "red";
     }

对任何问题发表评论:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    • 2020-03-21
    • 2022-06-24
    相关资源
    最近更新 更多