写一个函数,将前四个文本框的内容加起来放进第五个。然后前四个文本框的onchange事件调用上面的函数。

解决方案 »

  1.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>New Page 1</title>
    </head><body>
    <form name=frm>
    <input name=a1 onchange="SumFun();">
    <input name=a2 onchange="SumFun();">
    <input name=resultInput readOnly ></form>
    </body></html>
    <script>
    function SumFun()
    {
    document.all.resultInput.value=document.all.a1.value*1 + document.all.a2.value*1}
    </script>
      

  2.   

    function my_count(){
       document.all.text_total.value=parseFloat(document.all.text1.value)+parseFloat(document.all.text2.value)+parseFloat(document.all.text3.value);
    }<input type="text" name="text1" onchange="my_count()">
    <input type="text" name="text2" onchange="my_count()">
    <input type="text" name="text3" onchange="my_count()">
    <input type="text" name="text_total">
      

  3.   

    <script>
    function aa()
    {
        var t1=parseInt(document.form1.text1.value)
        var t2=parseInt(document.form1.text2.value)
        var t3=parseInt(document.form1.text3.value)
        var t4=parseInt(document.form1.text4.value)
        if(t1!=""|t2!=""|t3!=""|t4!="")
        {
              var t5=0
              document.form1.text5.value=t1+t2+t3+t4+t5
              var t5=document.form1.text5.value
        }
    }</script>
    <form name="form1">
    <input type="text" name="t1" value="" onblue="aa()">
    <input type="text" name="t2" value="" onblue="aa()">
    <input type="text" name="t3" vlaue="" onblue="aa()">
    <input type="text" name="t4" vlaue="" onblue="aa()">
    <input type="text" vlaue="" name="t5">
    </form>
      

  4.   

    <style>
    </style>
    <input type="text" id="n1"
     onkeypress="return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46"
     onpaste="return !clipboardData.getData('text').match(/\D/)"
     ondragenter="return false"
     style="ime-mode:Disabled"
     onkeypress="return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46"
     onpaste="return !clipboardData.getData('text').match(/\D/)"
     ondragenter="return false"
     style="ime-mode:Disabled" value="1">
    <input type="text" id="n2"
     onkeypress="return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46"
     onpaste="return !clipboardData.getData('text').match(/\D/)"
     ondragenter="return false"
     style="ime-mode:Disabled" value="2">
    <input type="text" id="n3"
     onkeypress="return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46"
     onpaste="return !clipboardData.getData('text').match(/\D/)"
     ondragenter="return false"
     style="ime-mode:Disabled" value="3">
    <input type="text" id="n4"
     onkeypress="return event.keyCode>=48&&event.keyCode<=57||event.keyCode==46"
     onpaste="return !clipboardData.getData('text').match(/\D/)"
     ondragenter="return false"
     style="ime-mode:Disabled" value="4">
    <input type="text" id="n5" readonly>
    <script>
    n5.setExpression("value","n1.value/1+n2.value/1+n3.value/1+n4.value/1")
    </script>