我正在尝试将内联 CSS 添加到 JS 计算(例如 3*2*1)以使其变为红色。我已经尝试了一个 span 标签,但它只显示计算而不是答案。我还尝试使用内部样式表。我该怎么做呢?这是 JS 小提琴:http: //jsfiddle.net/ytWea/
<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>