我試圖將內聯CSS添加到JS計算(例如3 * 2 * 1)以使其變爲紅色。 我已經嘗試了一個span標籤,但它只是顯示計算而不是答案。我也嘗試使用內部樣式表。我該怎麼做呢? 這是JS提琴:http://jsfiddle.net/ytWea/將CSS添加到JavaScript計算中
<html>
<head>
<script>
function volumeFields(){
document.getElementById("idLengthVolume");
document.getElementById("idWidthVolume");
document.getElementById("idHeightVolume");
document.getElementById("calcVolume");
}
function computeVolume(){
var x=document.getElementById("idLengthVolume").value;
var y=document.getElementById("idWidthVolume").value;
var z=document.getElementById("idHeightVolume").value;
var sVolume="The volume of your object is " + x * y * z
document.getElementById("idOutputVolume").innerHTML=sVolume;
}
</script>
</head>
<body onload="volumeFields()">
Insert the length of your object:<input type="text" size="20" id="idLengthVolume" /> <br/>
Insert the width of your object:<input type="text" size="20" id="idWidthVolume" /><br/>
Insert the height of your object:<input type="text" size="20" id="idHeightVolume" />
<input type="button" style="display:block" onclick="computeVolume()" value="Calculate" id="calcVolume"/>
<div id='idOutputVolume'></div>
</body>
</html>
請分享您的代碼。沒有代碼就無法回答你的問題。 – Gus
請閱讀這個問題,假裝你是我(對你的問題一無所知),並試圖回答這個問題。 –
Gus,我添加了我正在使用的代碼 – vman