js实现两个输入框中的数字相乘并自动将结果显示在第三个输入框

时间:2021-02-20 22:28:56

<script type="text/javascript">
function cal(ida,idb,idc)
   {
   var numa=Number(document.getElementById(ida).value);  
    var numb = Number(document.getElementById(idb).value);
   var numc=numa*numb;
   document.getElementById(idc).value=numc;
   }
</script>

<body>
<div>
  <input type="text" id="numa" name="numa" onkeyup="cal('numa','numb','numc')" />*  
  <input type="text" id="numb" name="numb" onkeyup="cal('numa','numb','numc')" />=
<input type="text" id="numc" name="numc" onkeyup="cal('numa','numb','numc')" />
</div>
</body>

js实现两个输入框中的数字相乘并自动将结果显示在第三个输入框