HTML:
<div id="tab_4" class="edit set"style="display: none"> <div id="sp_0" class="sp_0"> <table> <tr> <th>排序</th> <th>商城价</th> <th>市场价</th> <th>库存</th> <th>购买上限</th> <th>货号</th> <th style='display:none' >货位</th> <th>上架</th> <th>类型</th> <th>操作</th> </tr> <tr> <td width="10%" class="nwp"><input type="text" reg1="^[0-9]{0,2}$" desc="2个字符以内" id="sort" class="text20" name="sort1" maxlength="2" size="5" /></td> <td width="12%" class="nwp"><samp class="red"></samp> <input reg1="^[0-9]{1,7}\.{0,1}[0-9]{0,2}$" desc="保留2位小数,最多允许9位有效数字" type="text" id="skuPrice" name="skuPrice1"class="text20" size="5" onblur="changePri(this)"/></td> <td width="12%" class="nwp"><input type="text" id="marketPrice" name="marketPrice1" class="text20" reg1="^[0-9]{0,7}\.{0,1}[0-9]{0,2}$" desc="保留2位小数,最多允许9位有效数字" size="5" onblur="changePri(this)"/></td> <td width="12%" class="nwp"><samp class="red"></samp><input reg1="^(0|[1-9][0-9]{0,4})$" desc="5个字符以内非负整数" type="text" id="stockInventory" name="stockInventory1" class="text20" size="5" /></td> <td width="12%" class="nwp"><input reg1="^(.{0,0}|0|[1-9][0-9]{0,4})$" desc="请输入5个字符以内非负整数或为空 " type="text" id="skuUpperLimit" name="skuUpperLimit1" class="text20" size="5"/></td> <td width="12%" class="nwp"><input type="text" id="sku" name="sku1" class="text20" reg1="^[a-zA-Z0-9_\u4e00-\u9fa5]{0,20}$" desc="20个字符以内" size="5"/></td> <td width="12%" class="nwp" style='display:none;' ><input reg1="^[a-zA-Z0-9_\u4e00-\u9fa5]{0,20}$" desc="20个字符以内" type="text" id="location" name="location1" class="text20" size="5" /></td> </tr> </table> <input type="hidden" id="divNum" name="divNum" > </div> <div class="page_c"> <input type="button" id="button1" value="新增一排"> </div> </div>
jQuery:
$("#button1").click(function(){ var divNum=$("#divNum").val(); divNum=1; var divHtml=$("#sp_0").html(); divHtml="<div id='sp_"+divNum+"' class='sp_"+divNum+"'>"+divHtml+"</div>"; divHtml = divHtml.replace(/specradio1/g, "specradio"+divNum); // skuType1 showStatus1 sort1 skuPrice1 marketPrice1 stockInventory1 skuUpperLimit1 sku1 location1 divHtml = divHtml.replace(/skuType1/g, "skuType"+divNum); divHtml = divHtml.replace(/showStatus1/g, "showStatus"+divNum); divHtml = divHtml.replace(/sort1/g, "sort"+divNum); divHtml = divHtml.replace(/skuPrice1/g, "skuPrice"+divNum); divHtml = divHtml.replace(/marketPrice1/g, "marketPrice"+divNum); divHtml = divHtml.replace(/stockInventory1/g, "stockInventory"+divNum); divHtml = divHtml.replace(/skuUpperLimit1/g, "skuUpperLimit"+divNum); divHtml = divHtml.replace(/sku1/g, "sku"+divNum); divHtml = divHtml.replace(/location1/g, "location"+divNum); divHtml = divHtml.replace(/#sp_0/g, "#sp_"+divNum); //把复制的div追加在最后 $(".page_c").before(divHtml); $("#divNum").val(divNum); });
点击新增