很简单的一JS,提示缺少对象

remymartin 2010-03-03 10:51:07
<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)
...全文
253 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
aniubenben 2010-03-03
  • 打赏
  • 举报
回复
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 方法,另外空值需要判断
feelxym 2010-03-03
  • 打赏
  • 举报
回复
引用 5 楼 remymartin 的回复:
改成了
<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); 报错,崩溃....再等待


JS中没有 parseDouble()这个函数 只有 parseFloat() 及parseInt() 函数
feelxym 2010-03-03
  • 打赏
  • 举报
回复
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");
}
}
wszhoho 2010-03-03
  • 打赏
  • 举报
回复
document.getElementById("<%=txtCommision.ClientID%>").value
remymartin 2010-03-03
  • 打赏
  • 举报
回复
改成了
<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); 报错,崩溃....再等待
CHJGirl 2010-03-03
  • 打赏
  • 举报
回复
var cp=parseDouble(document.getElementById("txtCP").value);
var tp=100-cp;
这一段有问题,你应判断一下。
if(cp!=null)
{
var tp=100-cp;

}
wszhoho 2010-03-03
  • 打赏
  • 举报
回复
ReadOnly="True"的问题
cuike519 2010-03-03
  • 打赏
  • 举报
回复
parseDouble在哪定义的???
wen1512 2010-03-03
  • 打赏
  • 举报
回复
document.getElementById("txtCommision").value是空值,你可以在赋值前加个判断,如果为空就不赋值
mail_ylei 2010-03-03
  • 打赏
  • 举报
回复


<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>

remymartin 2010-03-03
  • 打赏
  • 举报
回复
谢谢,成功了,非常感谢各位
remymartin 2010-03-03
  • 打赏
  • 举报
回复
谢谢各位,我试一下看看

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧