如何计算所选复选框的总计?

发布于 2024-12-31 23:29:25 字数 1450 浏览 1 评论 0原文

我正在使用带有母版页的 ASP.NET。在其中我有一个嵌套的转发器:

<asp:Repeater ID=rptAttribute runat=server>
<ItemTemplate>
<h3><%# DataBinder.Eval(Container.DataItem, "Description") %></h3>
<div id="labelbox">
  <asp:TextBox ID="tSecionTotal" runat="server"></asp:TextBox>
  <div id="key1">
     <asp:Repeater ID="rptKey" runat="server">
       <ItemTemplate>
       <asp:CheckBox ID="rptKeySelection" runat="server" />
        <span><%# DataBinder.Eval(Container.DataItem, "Description") %></span>
       </ItemTemplate>
     </asp:Repeater>
  </div>
</ItemTemplate>
</asp:Repeater>

我想计算每个部分中复选框的值并进行两个显示。

  1. 使用复选框中的值更新文本框字段 (tSecionTotal)。
  2. 更新总文本/标签的总和。

呈现的 HTML 看起来像这样:

适当地打开和关闭交互
[ -- 显示本节总计的文本框 -- ]

[]尚未准备好进行互动 [+1]
[]没有使用正确的打开方式 [+1]
[]不保证没有其他需求[+2]
[]没有以适当的方式关闭交互[+5]>

表现出共同的礼貌(礼貌、耐心、同理心)
[ -- 显示本节总计的文本框 -- ]

[]没有使用常见的礼貌用语(请,谢谢)[+1]
[]对客户的语气/语调变化不恰当 [+2]
[]不当打断客户 [+5]
[]在需要时没有表现出同理心 [+2]

适应客户的知识和专业水平

[ -- 显示本节总计的文本框 -- ]

[]没有提供明确的说明(如何做)[+1]
[]没有提供明确的说明(如何)[+1]
[]没有提供明确的解释/教育(我们为什么这样做)[+3]
[]没有提供明确的解释/教育(我们为什么这样做)[+5]

总体总计 [ -- 显示总体总计的文本框 -- ]

I am using ASP.NET with a masterpage. Within it I have a nested repeater:

<asp:Repeater ID=rptAttribute runat=server>
<ItemTemplate>
<h3><%# DataBinder.Eval(Container.DataItem, "Description") %></h3>
<div id="labelbox">
  <asp:TextBox ID="tSecionTotal" runat="server"></asp:TextBox>
  <div id="key1">
     <asp:Repeater ID="rptKey" runat="server">
       <ItemTemplate>
       <asp:CheckBox ID="rptKeySelection" runat="server" />
        <span><%# DataBinder.Eval(Container.DataItem, "Description") %></span>
       </ItemTemplate>
     </asp:Repeater>
  </div>
</ItemTemplate>
</asp:Repeater>

I am wanting to calculate the values of the checkboxes within EACH section and make two displays.

  1. Have the textbox field (tSecionTotal) update with the value(s) from the checkboxes.
  2. Have an total text/label update with an overall total.

HTML rendered looks something like this:

Opened and closed the interaction appropriately
[ -- textbox to display total of this section -- ]

[]Was not ready to take the interaction [+1]
[]Did not use proper opening [+1]
[]Did not ensure that there were no other needs [+2]
[]Did not close the interaction in an appropriate manner [+5]>

Demonstrated common courtesy (polite, patient, empathetic)
[ -- textbox to display total of this section -- ]

[]Did not use common courteously words (please, thank you) [+1]
[]Inappropriate voice level / inflection with customer [+2]
[]Inappropriately interrupts customer [+5]
[]Did not demonstrate empathy when needed [+2]

Adapted to the customer's level of knowledge and expertise

[ -- textbox to display total of this section -- ]

[]Did not provide clear instructions (how to) [+1]
[]Did not provide clear instructions (how to) [+1]
[]Did not provide clear explanation / education (why we are doing this) [+3]
[]Did not provide clear explanation / education (why we are doing this) [+5]

Overall Totals [ -- textbox to display overall total -- ]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡的优雅 2025-01-07 23:29:25

您可以找到所有选中的项目,然后找到项目的值,添加它们并将其放在总计中

var Total = 0;
$("input:checked").each(function(i, selected){ 
  Total+= $(selected).parent(".keydiv").find(".myVal").val();
});

我在这里所做的是找到所有复选框,然后对于每个复选框,我都会找到其元素(例如 class=keydiv),然后我在 tr 的子元素中发现了具有您要添加的值的元素,我想它具有 css="myVal"。

假设你像这样渲染它。

<div id="key1" class="keydiv">
  check box
  <span class="myVal">5</span>
</div>

You can find all checked, then the values of the items, add them and place it on total

var Total = 0;
$("input:checked").each(function(i, selected){ 
  Total+= $(selected).parent(".keydiv").find(".myVal").val();
});

What I do here is to find all check box, then for each check box I go to find the souround it element (eg the class=keydiv), then I found inside the children of tr the element that have the value you won to add, I suppose that have the css="myVal".

Let say that if you render it like that.

<div id="key1" class="keydiv">
  check box
  <span class="myVal">5</span>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文