我有一些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;
}
答案 0 :(得分:0)
你没有得到任何元素,试试这个:
var arr = document.getElementsByClassName('det');