这个jquery有效:
但是,在我的C#页面中,这个jquery不起作用:
$(document).ready(function() {
var $txtFirstNumber = $('#<%= fvLineItemDetail.FindControl("txtFirstNumber").FindControl("txtData").ClientID %>');
var $txtSecondNumber = $('#<%= fvLineItemDetail.FindControl("txtSecondNumber").FindControl("txtData").ClientID %>');
var $txtTotal = $('#<%= fvLineItemDetail.FindControl("txtTotal").FindControl("literalStyle").ClientID %>');
$txtFirstNumber.live("change", calculate);
$txtSecondNumber.live("change", calculate);
function calculate() {
$txtTotal.text(parseInt($txtFirstNumber.val()) + parseInt($txtSecondNumber.val()));
}
});
当$ txtFirstNumber或$ txtSecondNumber中的值更改并失去焦点时,将调用calculate函数,但函数内的三个变量未定义且未被识别为全局变量。有什么想法吗?
编辑:这里有更多代码请求...
<asp:FormView ID="fvLineItemDetail" runat="server" EnableViewState="true">
<ItemTemplate>
<div class="col">
<control:TextBoxPDSL ID="txtFirstNumber" runat="server" cssClass="input" Text="5" />
</div>
<div class="col">
<control:TextBoxPDSL ID="txtSecondNumber" runat="server" cssClass="input" Text="3" />
</div>
<div class="col">
<control:TextBoxPDSL ID="txtTotal" IsReadOnlyLocked="true" runat="server" cssClass="input" />
</div>
</ItemTemplate>
</asp:FormView>