我有一个输入,我想在其中输入一些值,例如 [ [2, 4, 2] ] (以制作乘法矩阵)。现在我想读取该值,但不是“[ [2, 4, 2] ]”。有没有办法做到这一点?
<body>
<div id="main">
<form>
<input type="text" id="first"/>
<label for="first">example [ [2, 4, 2] ]</label>
<input type="text" id="second"/>
<select id="select">
<option value="add">Add</option>
</select>
<textarea></textarea>
</form>
</div>
<script type="text/javascript">
$( document ).ready(function() {
var select = $('#select');
function multiplyMatrix(m1, m2) {
var result = [];
for(var j = 0; j < m2.length; j++) {
result[j] = [];
for(var k = 0; k < m1[0].length; k++) {
var sum = 0;
for(var i = 0; i < m1.length; i++) {
sum += m1[i][k] * m2[j][i];
}
result[j].push(sum);
}
}
return result;
}
select.change(function(){
var
m1 = $('#first').val(),
m2 = $('#second').val();
multiplyMatrix(m1, m2);
console.log(multiplyMatrix(m1, m2));
});
});
</script>