zoukankan      html  css  js  c++  java
  • 如何让Table中的第一列和第二列的值相乘然后赋值给第三列

    因为需求的原因所以这样做,不废话了,直接上代码,我用的GridView绑定的数据,table也一样,因为GridView通过浏览器编译后的代码就是table。下面是aspx页面的Html代码:

    <asp:GridView ID="gv_new" runat="server" AutoGenerateColumns="False" CssClass="tb_data"
                            Width="100%" AllowPaging="True" PageSize="12" EmptyDataText="没有找到相关数据!" OnPageIndexChanging="gv_new_PageIndexChanging">
                            <Columns>
                                <asp:TemplateField HeaderText="发送时间" HeaderStyle-Width="15%">
                                    <ItemTemplate>
                                        <div style="text-align: center;">
                                            <%#Eval("MSG_DATE","{0:yyyy-MM-dd HH:mm:dd}")%>
                                        </div>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="发送人数" HeaderStyle-Width="80px">
                                    <ItemTemplate>
                                        <div style="text-align: center;" class="fsrs_num">
                                            <%#Eval("per_num")%>
                                        </div>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="折算短信条数" HeaderStyle-Width="10%">
                                    <ItemTemplate>
                                        <div style="text-align: center;" class="zsts_num">
                                            <%#Eval("MSG_TOTAL")%>
                                        </div>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="消费短信条数" HeaderStyle-Width="10%">
                                    <ItemTemplate>
                                        <div style="text-align: center;" class="xiaofei">
                                        </div>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="MSG_NUM" HeaderText="剩余短信条数" HeaderStyle-Width=""></asp:BoundField>
                            </Columns>
                        </asp:GridView>

    接下来就是Jquery代码了:

    <script type="text/javascript">
            $(function () {
                $("#gv_new tr").each(function () {
                    var fsrs = $(this).find(".fsrs_num");
                    var sdts = $(this).find(".zsts_num");
                    $(this).find(".xiaofei").text((parseInt(fsrs.text()) * parseInt(sdts.text())));
                });
            });
        </script>

    别忘了引用Jquery库哈,我这里就没有写出来了咯。

    总结下:我之前“fsrs_num“都是定义的Id,后来结果不对,在群里问了下,说用class最好,不容易出错,结果很满意,结果图如下:

  • 相关阅读:
    Solr 配置连接数据库
    最大利润
    分割金条的最小代价
    民居点亮
    一个会议室最多安排几场宣讲
    N皇后问题
    Integer的缓存机制
    Windows快捷键
    二叉树中两个节点的最低公共祖节点
    判断二叉树是不是完全二叉树
  • 原文地址:https://www.cnblogs.com/LoveQin/p/4610931.html
Copyright © 2011-2022 走看看