我有一些 javascript 和 html 代码,我想显示矩阵行列式的计算值,但该函数不想在输入位置显示它,我希望它显示在哪里,而是我得到一个空格。 HTML
<div id = "table">
<div id = "header">Wyznacznik [3x3]</div>
<form id = "row1">
<input type = "text" class = "det"/><!--first row-->
<input type = "text" class = "det"/>
<input type = "text" class = "det"/>
</form>
<form id = "row2">
<input type = "text" class = "det"/><!--second row-->
<input type = "text" class = "det"/>
<input type = "text" class = "det"/>
</form>
<form id = "row3">
<input type = "text" class = "det"/><!--third row-->
<input type = "text" class = "det"/>
<input type = "text" class = "det"/>
</form>
<div class = "count" onclick="det(3)"><a href = "#">Wylicz</a></div>
<input type = "text" id = "calcValue"/>
</div>
javascript
function det(size){
var arr = document.getElementsByClassName('det1');
var determinant = 0;
if(size == 2){
determinant = (arr[0].value*arr[3].value) - (arr[1].value*arr[2].value);
document.getElementById('calcValue1').value = determinant;
}
else if(size == 3){
determinant = (arr[0].value*((arr[4].value*arr[8].value) - (arr[5].value * arr[7].value))) -
(arr[1].value*((arr[3].value*arr[8].value) - (arr[5].value * arr[6].value))) +
(arr[2].value*((arr[3].value*arr[7].value) - (arr[4].value * arr[6].value)));
document.getElementById('calcValue').value = determinant;
}
return determinant;
}