javascript自动搜索

javascript自动搜索,javascript,Javascript,大家好,我正在用javascript进行自动求和,这在这里的链接中运行得很好,但我也想要反向自动求和 两者都很好,但各自独立。他们合作得不好 我使用这个代码 function startCalc(){ interval = setInterval("calc()",1); } function calc(){ one = document.autoSumForm.firstBox.value; two = document.autoSumFo

大家好,我正在用javascript进行自动求和,这在这里的链接中运行得很好,但我也想要反向自动求和

两者都很好,但各自独立。他们合作得不好

我使用这个代码

 function startCalc(){
      interval = setInterval("calc()",1);
    }
    function calc(){
      one = document.autoSumForm.firstBox.value;
      two = document.autoSumForm.secondBox.value; 
  third = document.autoSumForm.thirdBox.value; 
      document.autoSumForm.thirdBox.value = (one * 1) + ((two / 100) * one);
  //document.autoSumForm.firstBox.value = (third * 1) - ((two / 100) * third);
}
function stopCalc(){
  clearInterval(interval);
}
我的html是

<div style="width: 200px; text-align: center;">
    <form name="autoSumForm">
        <input class="right" type=text name="firstBox" value="" onFocus="startCalc();" onBlur="stopCalc();"><br>
        % <input class="right" type=text name="secondBox" value="10" onFocus="startCalc();" onBlur="stopCalc();"><br>
        = <input class="right" type=text name="thirdBox" value="" onFocus="startCalc();" onBlur="stopCalc();"><br>
    </form>
</div>


%
=

问题是,当我从第三个框中删除注释时,它就开始工作了。我希望autosum和reverse autosum同时使用。

在继续提问之前,您应该接受您提出的问题的一些答案。
<div style="width: 200px; text-align: center;">
    <form name="autoSumForm">
        <input class="right" type=text name="firstBox" value="" onkeyup="calc(1);"><br>
        % <input class="right" type=text name="secondBox" value="10" onkeyup="calc(2);"><br>
        = <input class="right" type=text name="thirdBox" value="" onkeyup="calc(3);"><br>
    </form>
</div>
​
function calc(box){
  one = document.autoSumForm.firstBox.value;
  two = document.autoSumForm.secondBox.value; 
  third = document.autoSumForm.thirdBox.value; 

  if(box == 1){
      document.autoSumForm.thirdBox.value = (one * 1) + ((two / 100) * one);;
  }else if(box == 2 || box == 3){
      document.autoSumForm.firstBox.value = (third * 1) - ((two / 100) * third);
  }

}