我創建了一個按鈕,該按鈕在JavaScript中生成隨機文本。我想將隨機生成的文本設置爲按鈕下方的居中,並具有以下顏色:#8a2be2。將樣式添加到java腳本字符串
<!-- arrays -->
function GetValue()
{
var myarray= new Array();
\t myarray[0]="The calcium in our bones and the iron in our blood come from ancient explosions of giant stars."
\t myarray[1]="The Chinese giant salamander can grow to be 6 feet (1.8 m) long, making it the largest salamander in the world."
<!--END--> \t
var random = myarray[Math.floor(Math.random() * myarray.length)];
//alert(random);
document.getElementById("fact button").innerHTML=random;
}
<input type="button" id="fact_button" value="Fact Button" onclick="GetValue();" />
<p id="fact button" ></p>
<h2 class="h2">click fact button for an amazing fact!</class> </h2>
你嘗試過什麼迄今爲止應用樣式,並且你想要的風格是什麼?按鈕或字符串,因爲你的問題似乎有點混淆你想要的樣式... – NewToJS
你可以添加CSS樣式,你面臨的問題是什麼? – Dij
是的,我添加了一個CSS檢查出來 –