簡體   English   中英

將內部 html 代碼中的文本顏色更改為紅色

[英]Change text color in the inner html code to red

document.getElementById("something").innerHTML = "My name is Jeremy Gordon and this is my Portfolio of my work in the QCC Software Engineering Micro Credential Boot Camp.";

我需要將innerHTML的文本更改為紅色。 如何使此字符串中的文本變為紅色。

您可以使用 DOM 樣式color屬性:

 document.getElementById( "something" ). innerHTML = "My name is Jeremy Gordon and this is my Portfolio of my work in the QCC Software Engineering Micro Credential Boot Camp."; document.getElementById( "something" ).style.color="red";
 <p id="something"></p>

這會有所幫助。

您可以在此處了解有關 setAttribute 方法的更多信息: https : //www.w3schools.com/jsref/met_element_setattribute.asp

  <script>
      document.getElementById("something").setAttribute("style", "color: red;");
  </script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM