<table width="100%" border="0">
                    <tr>
                        <td align="right">
                            返佣总金额</td>
                        <td align="left" colspan="3">
                            <asp:TextBox ID="txtCommision" runat="server" ReadOnly="True"></asp:TextBox></td>
                    </tr>
                    <tr>
                        [b]<td align="right">
                            导游返佣</td>
                        <td align="left" colspan="3">
                            <asp:TextBox ID="txtCP" runat="server" Width="48px" 
                            onBlur="Conculate();"></asp:TextBox>% =
                            <asp:TextBox ID="txtCCommision" runat="server"></asp:TextBox>
                        </td>                 </tr>
                    <tr>
                        <td align="right">
                            旅行社返佣</td>
                        <td align="left" colspan="3">
                            <asp:TextBox ID="txtTP" runat="server" Width="48px"></asp:TextBox>% =
                            <asp:TextBox ID="txtTCommision" runat="server"></asp:TextBox>
                         </td>
                    </tr>
                    <tr>
                        <td align="center" colspan="4">
                            <asp:Button ID="Button1" runat="server" Text="保存数据" /></td>
                    </tr>
                </table>
<script type="text/javascript">
function Conculate()
{
    var ct=parseDouble(document.getElementById("txtCommision").value);
    var cp=parseDouble(document.getElementById("txtCP").value);
    var tp=100-cp;
    document.getElementById("txtTP").value=tp;
    document.getElementById("txtCCommision").value=ct*cp/100;
    document.getElementById("txtTCommision").value=ct*tp/100;
   }   
</script> 只要焦点一离开 txtCP 就提示"缺少对象"
报错是 var ct=parseDouble(document.getElementById("txtCommision").value); var cp=parseDouble(document.getElementById("txtCP").value);这两行
但只要把的值在JS中提前赋好,就不会报错了,
document.getElementById()中的值都是用复制粘贴搞上去的,
实在不懂,望JS高手赐教!!!
(调试环境 VS2005)

解决方案 »

  1.   

    document.getElementById("txtCommision").value是空值,你可以在赋值前加个判断,如果为空就不赋值
      

  2.   

     var cp=parseDouble(document.getElementById("txtCP").value);
     var tp=100-cp; 
    这一段有问题,你应判断一下。
    if(cp!=null)
    {
     var tp=100-cp; }
      

  3.   

    改成了
    <script type="text/javascript">
    function Conculate()
    {
        var txt=document.getElementById("txtCommision");
        if(txt.value!=null)
        {
              ct=parseDouble(txt.value);
              var cp=parseDouble(document.getElementById("txtCP").value);
              var tp=100-cp;
            document.getElementById("txtTP").value=tp;
            document.getElementById("txtCCommision").value=ct*cp/100;
            document.getElementById("txtTCommision").value=ct*tp/100; 
          }
         else
         {
              alert("null value");
          }
       }
            </script>
    这一行 ct=parseDouble(txt.value); 报错,崩溃....再等待
      

  4.   

    document.getElementById("<%=txtCommision.ClientID%>").value
      

  5.   

    function Conculate() 
                    {
                        var txt = document.getElementById("txtCommision");                    
                        if (txt.value != null && txt.value!="") {
                            ct = parseFloat(txt.value);
                            var cp = parseFloat(document.getElementById("txtCP").value);
                            var tp = 100 - cp;
                            document.getElementById("txtTP").value = tp;
                            document.getElementById("txtCCommision").value = ct * cp / 100;
                            document.getElementById("txtTCommision").value = ct * tp / 100;
                        }
                        else {
                            alert("null value");
                        }
                      }  
      

  6.   


    JS中没有 parseDouble()这个函数 只有 parseFloat() 及parseInt() 函数
      

  7.   

           var ct=parseFloat( (document.getElementById("txtCommision").value == "") ?0.0:document.getElementById("txtCommision").value);  
        var cp=parseFloat( (document.getElementById("txtCP").value == "") ?0.0:document.getElementById("txtCP").value);    貌似只有parseFloat 方法,另外空值需要判断
      

  8.   


        
            <script type="text/javascript">
            function Conculate()
            {
                var txt=document.getElementById("txtCommision"); 
                if(txt.value.length>0)
                { 
                    var ct=parseFloat(txt.value); 
                    var cp=parseFloat(document.getElementById("txtCP").value);
                    var tp=100-cp;
                    document.getElementById("txtTP").value=tp;
                    document.getElementById("txtCCommision").value=ct*cp/100;
                    document.getElementById("txtTCommision").value=ct*tp/100;
                }
             
              } 
            </script>