zoukankan      html  css  js  c++  java
  • 客户端自动累加

        有的时候需要在输入数量的同时,实时计算出输入的总和,这就要借助于Javascript

    <script language="JavaScript">
    function count() 
    {     
            
    var one = document.thisform.one.value;
            
    var two = document.thisform.two.value;
            
    if ((one!="")&&(two!=""))
            {
                    document.thisform.total.value 
    = parseInt(one) + parseInt(two);
            }
            
    else
            {
                    document.thisform.total.value 
    = "";
            }  
    }
    </script>

           需要注意的是, 取得的one和two的值,由于是字符型, 需要先将one , two转换成数字类型. 否则 计算出的结果会变成1+1=11
    所用到的都是客户端控件

    <table width="100%" cellspacing="1" cellpadding="5" align="center" class="bg_tablemain">
     
    <form action="" method="POST" name="thisform">
     
    <tr>
     
    <td align="right">一月數量</td>
     
    <td><input type="text" name="one" size="4" value="" onKeyUp="value=value.replace(/\D+/g,'');
        count();"
    ></td>
     
    <td align="right">2月數量</td>
     
    <td><input type="text" name="two" size="8" onKeyUp="count();" ></td>
     
    <td align="right">總數量:</td>
     
    <td><input type="text" name="total" size="12" readonly value="" style="color: #CC0000"></td>
     
    </tr>
     
    </form>
     
    </table> 
  • 相关阅读:
    第十一章 表单与验证
    第十章 日期与时间
    第九章 正则表达式
    第八章 字符串处理
    纯C实现面向对象之接口编程
    csharp 面向对象编程
    cpp面向对象编程
    javascriptMVC框架面向对象编程
    堆栈的区别
    Java堆栈简介
  • 原文地址:https://www.cnblogs.com/maoniu602/p/1315944.html
Copyright © 2011-2022 走看看