我有3個相同長度的數組。我想減去前兩個數組中的值,而不點擊按鈕,如果答案是否定的,我得到該數組的索引,並從第三個數組中顯示一個隱藏的輸入字段(以html表示)其數組索引對應於負數的數組索引。如何使用javascript減去數組中的值
例如:
//assuming this is the first array
array('10','2','3','4','5');
//and assuming this is the second array
array('9','1','4','3','7');
我想從第一陣列中減去所述第二值,使得i具有的結果,例如:
array('1','1','-1','1','-2');
上述結果確定將顯示哪些輸入字段(來自第三個數組)。例如要顯示的輸入字段是那些數組索引是2和4
這裏是我的代碼輸入字段的第3個數組:
<?php while($roww = mysql_fetch_array($result)) { ?>
<input type='text' name="reason[]" class="explanation">
<?php } ?>
有沒有什麼辦法可以讓上面的可能嗎?
到目前爲止,這是我已經嘗試過,雖然我還沒有應用arrays..just對樣品我在互聯網上發現了一個輕微的更新...
<html>
<head>
<script src="jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".explanation").hide();
var input1_ = document.getElementById('num1');
var input_ = document.getElementById('num2');
function sub(){
var answer = (parseInt(input1_.value) - parseInt(input2_.value));
if(answer < 0){
$(".explanation").show();
}else $(".explanation").hide();
}
document.getElementById('num1').onkeyup = function() {
sub();
};
document.getElementById('num2').onkeyup = function() {
sub();
};
});
</script>
</head>
<body>
<input type='number' id='num1' value="0">
<input type='number' id='num2' value="0">
<input type='text' class='explanation' value="0">
</body>
</html>
是的,這是可能的。你有什麼嘗試? – vlaz
我已經更新了這個問題,以顯示我迄今爲止所做的事情。 – Kenn