1
我有一個輸入,我想把一些值[[2,4,2]](做一個乘法矩陣)。現在我想讀取值但不是「[[2,4,2]]」。有沒有辦法做到這一點?jQuery矩陣輸入值
<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>