我试图将内联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