• jQuery遍历Table tr td td中包含标签


     function shengchen() {

                 var arrTR = $("#tbModule").children();

                 var Context="";

                 $("#tbModule").find("tr").each(function () {

                     var arrtd = $(this).children();

                     tdContext = $.trim(arrtd.eq(0).text());

                     tdContext += ":" + arrtd.eq(2).find("input").val() + ";";

                     Context += tdContext;

                 })

                 Context= Context.substring(Context.indexOf(";")+1);

                 $("#txtContent").val(Context);

             }

     


    我这里是通过点击 来获取 table中的td的数据,其中一个td包含一个input标签

    通过

    $("#tbModule").find("tr").each(function () {})

    来获回去所有行的对象,通过

    $(this).children();

    来获取行内所有的td,通过

    arrtd.eq(0)

    来获取某个制定的td,这里你也可以用循环来获取数据,注释的部分是获取td中标签的值

                     for (var k = 0; k < arrtd.length; k++) {

                         var con = arrtd.eq(k).text();

                         //var con = arrtd.eq(2).find("input").val();

                    }

     全部代码

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BianLi.aspx.cs" Inherits="jQueryDemoWeb.BianLi" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <title></title>

        <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

        <script>

            function shengchen() {

                var arrTR = $("#tbModule").children();

                var Context = "";

                $("#tbModule").find("tr").each(function () {

                    var arrtd = $(this).children();

                    tdContext = $.trim(arrtd.eq(0).text());

                    tdContext += ":" + arrtd.eq(2).find("input").val() + ";";

                    Context += tdContext;

    //                for (var k = 0; k < arrtd.length; k++) {

    //                    var con = arrtd.eq(k).text();

    //                    //var con = arrtd.eq(2).find("input").val();

    //                }

                })

                Context = Context.substring(Context.indexOf(";") + 1);

                $("#txtContent").val(Context);

            }

       

        </script>

    </head>

    <body>

        <form id="form1" runat="server">

        <div>

            <table id="tbModule" width="100%" cellpadding="0" cellspacing="0" style="border-right: 1px solid #D2D2D2;

                border-left: 1px solid #D2D2D2; border-bottom: 1px solid #D2D2D2;">

                <tr>

                    <td class="tb_d1" style=" 60px;">

                        编号

                    </td>

                    <td class="tb_d1" style=" 60px;">

                        名称

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        终端数量

                    </td>

                </tr>

                <tr id='1'>

                    <td id='dt11' class="tb_d1" style=" 60px;">

                        1

                    </td>

                    <td id="dt21" class="tb_d1" style=" 60px;">

                        前台收银

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl00$txtCount" type="text" value="3" id="rptModule_ctl00_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='2'>

                    <td id='dt12' class="tb_d1" style=" 60px;">

                        2

                    </td>

                    <td id="dt22" class="tb_d1" style=" 60px;">

                        打印服务器

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl01$txtCount" type="text" value="3" id="rptModule_ctl01_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='3'>

                    <td id='dt13' class="tb_d1" style=" 60px;">

                        3

                    </td>

                    <td id="dt23" class="tb_d1" style=" 60px;">

                        无线服务器

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl02$txtCount" type="text" value="3" id="rptModule_ctl02_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='4'>

                    <td id='dt14' class="tb_d1" style=" 60px;">

                        4

                    </td>

                    <td id="dt24" class="tb_d1" style=" 60px;">

                        会员管理

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl03$txtCount" type="text" value="3" id="rptModule_ctl03_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='5'>

                    <td id='dt15' class="tb_d1" style=" 60px;">

                        5

                    </td>

                    <td id="dt25" class="tb_d1" style=" 60px;">

                        库存管理

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl04$txtCount" type="text" value="3" id="rptModule_ctl04_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='6'>

                    <td id='dt16' class="tb_d1" style=" 60px;">

                        6

                    </td>

                    <td id="dt26" class="tb_d1" style=" 60px;">

                        经理查询

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl05$txtCount" type="text" value="3" id="rptModule_ctl05_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='7'>

                    <td id='dt17' class="tb_d1" style=" 60px;">

                        7

                    </td>

                    <td id="dt27" class="tb_d1" style=" 60px;">

                        数据维护

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl06$txtCount" type="text" value="3" id="rptModule_ctl06_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='10'>

                    <td id='dt110' class="tb_d1" style=" 60px;">

                        10

                    </td>

                    <td id="dt210" class="tb_d1" style=" 60px;">

                        成本管理

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl07$txtCount" type="text" value="3" id="rptModule_ctl07_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='17'>

                    <td id='dt117' class="tb_d1" style=" 60px;">

                        17

                    </td>

                    <td id="dt217" class="tb_d1" style=" 60px;">

                        预订平台

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl08$txtCount" type="text" value="3" id="rptModule_ctl08_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='20'>

                    <td id='dt120' class="tb_d1" style=" 60px;">

                        20

                    </td>

                    <td id="dt220" class="tb_d1" style=" 60px;">

                        快餐收银

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl09$txtCount" type="text" value="3" id="rptModule_ctl09_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='21'>

                    <td id='dt121' class="tb_d1" style=" 60px;">

                        21

                    </td>

                    <td id="dt221" class="tb_d1" style=" 60px;">

                        财务管理

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl10$txtCount" type="text" value="3" id="rptModule_ctl10_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='22'>

                    <td id='dt122' class="tb_d1" style=" 60px;">

                        22

                    </td>

                    <td id="dt222" class="tb_d1" style=" 60px;">

                        营销管理

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl11$txtCount" type="text" value="3" id="rptModule_ctl11_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='23'>

                    <td id='dt123' class="tb_d1" style=" 60px;">

                        23

                    </td>

                    <td id="dt223" class="tb_d1" style=" 60px;">

                        厨房监控

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl12$txtCount" type="text" value="3" id="rptModule_ctl12_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

                <tr id='24'>

                    <td id='dt124' class="tb_d1" style=" 60px;">

                        24

                    </td>

                    <td id="dt224" class="tb_d1" style=" 60px;">

                        总部管理

                    </td>

                    <td class="tb_d2" style=" 80px;">

                        <input name="rptModule$ctl13$txtCount" type="text" value="3" id="rptModule_ctl13_txtCount"

                            style=" 60px;" />

                    </td>

                </tr>

            </table>

        </div>

        <br />

        <a href="javascript:shengchen();">生成</a>

        <br />

        <br />

        <input name="tt" id="txtContent" type="text" style=" 977px;" />

        </form>

    </body>

    </html>

    佛为心,道为骨,儒为表,大度看世界; 技在手,能在身,思在脑,从容过生活; 三千年读史,不外功名利禄; 九万里悟道,终归诗酒田园;
  • 相关阅读:
    Python编码风格
    CI持续集成—记一次jenkins安装及ldap配置
    mysql主从同步失败处理
    redis优化
    sysbench
    Ubuntu12.04 Installation and Subversion(svn)
    MySQL 5.7 CLUSTER NDB 7.5 创建磁盘表 undo logfile group tablespace 内存表修改为磁盘表
    Java异步调用Future对象
    Java宝典(二)
    Java宝典(一)
  • 原文地址:https://www.cnblogs.com/taofx/p/4137034.html
Copyright © 2020-2023  润新知