【发布时间】:2017-02-09 01:45:45
【问题描述】:
我有 3 个长度相同的数组。我想减去前两个数组中的值,而不单击按钮,如果答案是否定的,我会得到该数组编号的索引,并从第三个数组中显示一个隐藏的输入字段(在 html 中),其数组索引对应负数的数组索引。
例如:
//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');
我想从第一个数组中减去第二个的值,这样我就有了结果,例如:
array('1','1','-1','1','-2');
上述结果决定了要显示哪些输入字段(来自第三个数组)。例如要显示的输入字段是数组索引为 2 和 4 的那些
这是我的第三个输入字段数组的代码:
<?php while($roww = mysql_fetch_array($result)) { ?>
<input type='text' name="reason[]" class="explanation">
<?php } ?>
有什么办法可以让上述事情成为可能吗?
到目前为止,这是我尝试过的,虽然我还没有应用数组..只是对我在互联网上找到的示例进行了轻微更新......
<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>
【问题讨论】:
-
是的,有可能。你试过什么?
-
我已经更新了问题,以显示我到目前为止所做的事情..
标签: javascript php jquery html arrays