【发布时间】:2012-05-23 19:49:05
【问题描述】:
我需要在 asp.net 页面中使用来自用户控件标签的值进行计算。
用户控件标签为:
<asp:Label ID="LblInvoicePriceValue" runat="server" ></asp:Label>
我这样包含它:
<Controls:VehicleInformation ID="VehicleInformationControl" runat="server" />
我的 jquery 函数类似于: 请参阅第 1 点和第 2 点。
<script type="text/javascript">
$(document).ready(function () {
alert('call function to do calculation here');
// 1. Find in the vehicle information user control the invoiced ammount label
// 2. Find the vat excluded value **after** it was typed in the textbox
// 3. If invoiced ammount is greater than zero, then
// 3.a Find Label Percentage
// 3.b Label.Text = (AmmountWithoutVat/InvoicedAmmount)*100 + '%'
});
</script>
生成的 HTML:UPdate1
对于标签:
<span id="MainContent_VehicleInformationControl_LblInvoicePriceValue" class="bold"></span>
对于文本框:
<input name="ctl00$MainContent$TxtVatExcluded" type="text" id="TxtVatExcluded" class="calculation" />
更新 2:
<script type="text/javascript">
$(document).ready(function () {
alert('call function to do calculation here');
$("#TxtVatExcluded").keypress(function() {
var invoiceprice = $("#MainContent_VehicleInformationControl_LblInvoicePriceValue").text();
var vatexcluced = $("#TxtVatExcluded").val();
var lblPercentage = $("#MainContent_LblPercentage");
if (invoiceprice > 0) {
lblPercentage.text((vatexcluced / invoiceprice) * 100);
}
})
// 1. Find in the vehicle information user control the invoiced ammount label
// 2. Find the vat excluded value after it was typed in the textbox
// 3. If invoiced ammount is greater than zero, then
// 3.a Find Label Percentage
// 3.b Label.Text = (AmmountWithoutVat/InvoicedAmmount)*100 + '%'
});
</script>
【问题讨论】:
-
您能否包含控件/标签生成的实际 HTML 输出(使用视图源就足够了)...
-
如果您已经阅读了 jQuery 大约一两个小时,这应该不会太难。 $("#theID").val() 将为您提供该 id 的值, $("#theID").blur( function () {}) 将让您定义焦点离开该字段时会发生什么(假设theID 是一个输入元素)。
标签: javascript jquery asp.net jquery-selectors