<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)
<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)
解决方案 »
- FtpWebRequest为什么不能用做web上传文件
- 一个验证控件RequiredFieldValidator的问题!
- 网站开发时用了微软的AjaxToolkit,发布上传后出错
- 如何将FORM表单传到另一个页面中去呢?(急)
- asp.net中制作框架网页 怎样在框架整体刷新的情况下 子框架里面的页面仍然保持状态?
- 关于淘宝SDK的疑问
- 请问如果将windows窗体设为登陆窗体啊?
- 关于Session的问题
- 如何在.net中读取文本文件?
- 求救:在aspx文件中如何实现那种随拉动滚动条而移动的广告窗口(layer?)?
- Gridview分页问题
- javascript 不能读取 服务器端 XML
var tp=100-cp;
这一段有问题,你应判断一下。
if(cp!=null)
{
var tp=100-cp; }
<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); 报错,崩溃....再等待
{
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");
}
}
JS中没有 parseDouble()这个函数 只有 parseFloat() 及parseInt() 函数
var cp=parseFloat( (document.getElementById("txtCP").value == "") ?0.0:document.getElementById("txtCP").value); 貌似只有parseFloat 方法,另外空值需要判断
<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>