English 中文(简体)
能否同时动态添加两行?
原标题:Is it possible to dynamically add 2 rows at once?

""https://i.sstatic.net/vKHqW.jpg" alt="在这里输入图像描述"/ >

表格上有两排必须重复四次

因此,与其同时显示8行,不如同时显示头2行,用一个按钮显示头2行“添加额外的行”

如果用户单击按钮,则自动添加两行。

从下面的代码,每个代码开头是... 和结尾显示4次。

2 行 显示 8 次 合并

不总是填满行。因此,如果用户点击一个按钮,在需要时添加两行,这将是一件好事。

我有一个js可以加一行,但我无法同时加2行。

代码是这样的... 我试图自动添加 看起来像。

<script type= text/javascript >//<![CDATA[
    $(window).load(function () {
        var index = 1;
        $(document).ready(function () {
            $("#more").click(function () {
                addRow(1)
                //alert($("#form1").html()); Uncomment to view updated form html
            });
        });


        function addRow(rowCount) {
            for (i = 0; i < rowCount; i++) {
                index = index + 1;
                $("#form1").append($("#template").html().replace(/_1/g, "_" + index));
            }
        }

    });//]]>  

</script>

      <div id="template">
                  <table border="1" bordercolor="black" cellspacing="0">
            <tr>
            <td>

      <table style="border-top-width:2px;border-top-style:solid;border-top-color:#000000">
            <tr valign="top">
                 <td valign="middle" style="font-size:large;font-weight:bold;" class="style4"></td>
                <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Line #<br />
                    <asp:TextBox ID="TextBox24" runat="server" Width="25px" />
                </td>
                <td style="width:135px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                   Code<br />
                     <asp:TextBox ID="TextBox38" runat="server" Width="25px" />
                </td>
                 <td style="width:125px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Document Reference<br />
                    <asp:TextBox ID="TextBox25" runat="server" Width="45px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Line<br />
                    <asp:TextBox ID="TextBox26" runat="server" Width="25px" />
                </td>
                 <td style="width:115px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    PC COMM LN<br />
                    <asp:TextBox ID="TextBox27" runat="server" Width="25px" />
                </td>
                 <td style="width:115px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Vendor Invoice #<br />
                    <asp:TextBox ID="TextBox28" runat="server" Width="85px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                  Fund<br />
                      <asp:DropDownList id="txtfund" runat="server"></asp:DropDownList>
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Agency<br />
                      <asp:DropDownList id="txtagency" runat="server"></asp:DropDownList>
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Org.<br />
                     <asp:DropDownList id="txtorg" runat="server"></asp:DropDownList>
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Sub<br />
                    <asp:TextBox ID="TextBox32" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Activity<br />
                    <asp:TextBox ID="TextBox33" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Object<br />
                    <asp:TextBox ID="TextBox34" runat="server" Width="25px" />
                </td>
                 <td style="width:115px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Sub<br />
                    <asp:TextBox ID="TextBox35" runat="server" Width="25px" />
                </td>
                 <td style="width:115px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                   Rev Source<br />
                    <asp:TextBox ID="TextBox36" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;">
                    Sub<br />
                    <asp:TextBox ID="TextBox37" runat="server" Width="25px" />
                </td>
            </tr>
        </table>   

        <table style="border-top-width:2px;border-top-style:solid;border-top-color:#000000">
            <tr valign="top">
                 <td valign="middle" style="font-size:large;font-weight:bold;" class="style4"></td>
                <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    <br /><br />Job #<br />
                    <asp:TextBox ID="TextBox39" runat="server" Width="45px" />
                </td>
                <td style="width:135px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    <br />
                    Rept<br />Category<br />
                     <asp:TextBox ID="TextBox40" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    <br /><br />BS Acct<br />
                    <asp:TextBox ID="TextBox41" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                   <br /><br /> DISC<br />
                    <asp:TextBox ID="TextBox42" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    <br />Description (30) Spaces<br />
                    <asp:TextBox ID="TextBox403" runat="server" onKeyUp="javascript:Count(this,30);" onChange="javascript:Count(this,30);" TextMode="MultiLine" Columns="30" Rows="2" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    <br /><br />Quant.<br />
                    <asp:TextBox ID="TextBox44" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                   <br /><br /> Amount<br />
                    <asp:TextBox ID="TextBox45" runat="server" Width="55px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                   Inc<br />/<br />Dec<br />
                    <asp:TextBox ID="TextBox46" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;">

                    P<br />/<br />F<br />
                    <asp:TextBox ID="TextBox47" runat="server" Width="25px" />
                </td>
            </tr>
        </table>   
        </td>
        </tr>
        </table>        
        </div>

      <a href="#" id="more">Add More Rows</a>
     <div class="noprint" style="border-top-width:2px;border-top-style:solid;border-top-color:#000000"">
            <asp:Button runat="server" ID="btnSAP" Text="Save" OnClientClick=" return validate()" />
             <asp:Button ID="btnClear" OnClick="ClearFilter" height="27px" Text="Reset" runat="server" class="btn" /> 
            <asp:Button runat="server" ID="btnCancel" Text="Exit Form" />
             <!-- Results -->
            <asp:Label ID="lblResult" style ="font-weight:bold; font-size:large" runat="server"></asp:Label>
      </div>
   </form>

这是与Mohammed(感谢)创造的小提琴的链接

http://jsfiddle.net/TE6ac/" rel="没有跟随 nofollown noreferrer" >http://jsfiddle.net/TE6ac/

我也发现了这个例子:

http://jsfiddle.net/nick_craver/BE5Lr/" rel="没有跟随 Noreferrer">http://jsfiddle.net/nick_craver/BE5Lr/

如果我重复那个...

问题在于我还有更多, 也不知道从哪里开始和停止。

最佳回答

Take a look at this fiddle here: http://jsfiddle.net/dharmavir/9nHbs/ it should help.!

<div id="template">
                  <table border="1" bordercolor="black" cellspacing="0">
            <tr>
            <td>

      <table style="border-top-width:2px;border-top-style:solid;border-top-color:#000000">
            <tr valign="top">
                 <td valign="middle" style="font-size:large;font-weight:bold;" class="style4"></td>
                <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Line #<br />
                    <asp:TextBox ID="TextBox24" runat="server" Width="25px" />
                </td>
                <td style="width:135px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                   Code<br />
                     <asp:TextBox ID="TextBox38" runat="server" Width="25px" />
                </td>
                 <td style="width:125px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Document Reference<br />
                    <asp:TextBox ID="TextBox25" runat="server" Width="45px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Line<br />
                    <asp:TextBox ID="TextBox26" runat="server" Width="25px" />
                </td>
                 <td style="width:115px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    PC COMM LN<br />
                    <asp:TextBox ID="TextBox27" runat="server" Width="25px" />
                </td>
                 <td style="width:115px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Vendor Invoice #<br />
                    <asp:TextBox ID="TextBox28" runat="server" Width="85px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                  Fund<br />
                      <asp:DropDownList id="txtfund" runat="server"></asp:DropDownList>
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Agency<br />
                      <asp:DropDownList id="txtagency" runat="server"></asp:DropDownList>
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Org.<br />
                     <asp:DropDownList id="txtorg" runat="server"></asp:DropDownList>
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Sub<br />
                    <asp:TextBox ID="TextBox32" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Activity<br />
                    <asp:TextBox ID="TextBox33" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Object<br />
                    <asp:TextBox ID="TextBox34" runat="server" Width="25px" />
                </td>
                 <td style="width:115px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    Sub<br />
                    <asp:TextBox ID="TextBox35" runat="server" Width="25px" />
                </td>
                 <td style="width:115px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                   Rev Source<br />
                    <asp:TextBox ID="TextBox36" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;">
                    Sub<br />
                    <asp:TextBox ID="TextBox37" runat="server" Width="25px" />
                </td>
            </tr>
        </table>   

        <table style="border-top-width:2px;border-top-style:solid;border-top-color:#000000">
            <tr valign="top">
                 <td valign="middle" style="font-size:large;font-weight:bold;" class="style4"></td>
                <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    <br /><br />Job #<br />
                    <asp:TextBox ID="TextBox39" runat="server" Width="45px" />
                </td>
                <td style="width:135px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    <br />
                    Rept<br />Category<br />
                     <asp:TextBox ID="TextBox40" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    <br /><br />BS Acct<br />
                    <asp:TextBox ID="TextBox41" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                   <br /><br /> DISC<br />
                    <asp:TextBox ID="TextBox42" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    <br />Description (30) Spaces<br />
                    <asp:TextBox ID="TextBox403" runat="server" onKeyUp="javascript:Count(this,30);" onChange="javascript:Count(this,30);" TextMode="MultiLine" Columns="30" Rows="2" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                    <br /><br />Quant.<br />
                    <asp:TextBox ID="TextBox44" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                   <br /><br /> Amount<br />
                    <asp:TextBox ID="TextBox45" runat="server" Width="55px" />
                </td>
                 <td style="width:105px;border-right-width:2px;border-right-style:solid;border-right-color:#000000">
                   Inc<br />/<br />Dec<br />
                    <asp:TextBox ID="TextBox46" runat="server" Width="25px" />
                </td>
                 <td style="width:105px;">

                    P<br />/<br />F<br />
                    <asp:TextBox ID="TextBox47" runat="server" Width="25px" />
                </td>
            </tr>
        </table>   
        </td>
        </tr>
        </table>        
        </div>

<table id="sometable">
<tbody>
</tbody>
</table>
<table id="anothertable">
<tr>
<td> some other table </td>
</tr>
</table>
      <a href="#" id="more">Add More Rows</a>
     <div class="noprint" style="border-top-width:2px;border-top-style:solid;border-top-color:#000000"">

      </div>
<input type="submit" value="Save" />
      <input type="reset" value="Reset" />
   </form>

标注代码 :

<script type="text/javascript">
var index = 1;
        $(document).ready(function () {
            $("#more").click(function () {
                addRow(1);
                //alert($("#form1").html()); Uncomment to view updated form html
            });
        });


        function addRow(rowCount) {
            for (i = 0; i < rowCount; i++) {
                index = index + 1;
$("#sometable").append($("#template").html().replace(/_1/g, "_" + index));
            }
        }
</script>
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签