有是传递参数的问题!
1、C#后台代码:
//插入状态时,用于计算金额.
if (e.Item.ItemType == ListViewItemType.InsertItem) {
TextBox FPriceTextBox = (TextBox)e.Item.FindControl("FPriceTextBox"); //单价的控件.
TextBox FCountTextBox = (TextBox)e.Item.FindControl("FCountTextBox"); //数量的控件.
TextBox FAcountTextBox = (TextBox)e.Item.FindControl("FAcountTextBox"); //金额的控件.
//设置额外属性,用户从客户端的该属性中寻找该控件.
FPriceTextBox.Attributes["myId"] = FPriceTextBox.ClientID;
FCountTextBox.Attributes["myId"] = FCountTextBox.ClientID;
FAcountTextBox.Attributes["myId"] = FAcountTextBox.ClientID;
//为单价、数量控件相应事件(焦点离开时计算金额)
FPriceTextBox.Attributes["onblur"] = "calcuAcount('" + FPriceTextBox.ClientID + "," + FCountTextBox.ClientID + ",
" + FAcountTextBox.Attributes["myId"] + "')";
FCountTextBox.Attributes["onblur"] = "calcuAcount('" + FPriceTextBox.ClientID + "," + FCountTextBox.ClientID + "," + FAcountTextBox.ClientID + "')";
2、jquery方法:
function calcuAcount(price, count,
acount) {
if ($("text[myId=" + acount + "]")) {
alert(acount); //这里总是undifined。
var strPrice = $("text[myId=" + price + "]").val();
var strCount = $("text[myId=" + count + "]").val();
var intPrice = parseFloat(strPrice, 10);
var intCount = parseFloat(strCount, 10);
$("text[myId=" + acount + "]").val(intPrice * intCount);
}
}
description:
对于上次2010的一个bug,我查了一下资料,然后想避开那个bug,需求是:
对于前面的两个文本框,当焦点离开时,自动计算金额,并赋值给第3个文本框,
在后台代