은이 같은, JS에서 간단한 승산을 계산하기 위해 시도하고있다 : =
A * B = C
위해 D * E = F
G의 *의 H I
총계 = C + F + IHTML 페이지의 값을 사용하여 JavaScript에서 값을 계산하는 방법은 무엇입니까?
그러나 총합은 예상보다 훨씬 큽니다. 곱셈에 문제가 있거나 페이지에서 값을 잘못 읽었습니까?
<html>
<head>
<script>
calculate = function(totalElement)
{
if (totalElement)
{
var calculation = '';
var overall = '';
var fields = new Array();
var theElement = document.getElementById(totalElement);
var userInputs = myform.elements;
var the_type = '';
for (var f = 0; f < userInputs.length; f++)
{
if (userInputs[f].className=='special_value')
{
if(userInputs[f].value != "")
{
document.getElementById("price4").value+=+userInputs[f].value;
}
}
}
}
}
</script>
</head>
<body>
<form name="myform">
A<input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value" value="" type="text" name="price">
B<input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value" type="text" value="" name="price2">
C<input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value" type="text"value="" name="price4" id="price4"> <Br/>
D<input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value" value="" type="text" name="price5">
E<input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value" type="text" value="" name="price6">
F<input onKeyPress="calculate('total');" onBlur="calculate('total');" class="special_value" type="text"value="" name="price7" id="price7"> <Br/>
Total<input class="special_value" value="" id="total" type="text" name="total"> <Br/>
<!-- <div id="total"></div> -->
<input onClick="calculate('total');" type="button" name="button" value="re-calculate">
</form>
</body>
</html>
* 그러나, 값이 날 너무 큰거야 * 그래서 질문은 무엇인가.? – VisioN
여기에 무슨 일이 ... document.getElementById ("price4"). value + = + userInputs [f] .value; .. + = + ... 흠 .. –
이것은 잠시 읽은 것보다 덜 이해합니다. 'A * B = C D * E = F G * H = I 총계 = C + F + I'. 이 질문은 일반적으로 의미가 없습니다. – jahroy