我以下HTML塊:如何追加一個HTML塊相同<form>標籤內現有的HTML塊?
<form action="add_rebate_by_quat_volume.php" role="form" method="post">
<div class="row">
<input type="hidden" class="form-control" name="op" id="op" value="preview">
<input type="hidden" class="form-control" name="id" id="id" value="">
<input type="hidden" class="form-control" name="form_submitted" id="form_submitted" value="yes">
<div class="col-xs-2">
</div>
<div style="float: clear;"></div>
<div style="margin-left: 12px" class="col-xs-4">
<div class="form-group">
<label for="company_name" class="col-lg-4">Manufacturer<span style="color:#FF0000">*</span></label>
<div class="col-lg-7">
<select id="company_id" name="company_id" class="form-control" onchange="GetAllProductByManufacturerID(this.value)">
<option value="" selected='selected'>Select Manufacturer</option>
<option value="33" >Eywa Solutions</option>
<option value="37" >Amazon</option>
<option value="40" >Test</option>
<option value="42" >RK</option>
<option value="46" >Santa Margherita</option>
</select>
</div>
</div>
</div>
<div style="margin-left: -61px" class="col-xs-4">
<div class="form-group">
<div class="col-lg-7">
<button style="float:right" class="btnAdd" type="button" class="btn btn-default" onclick="add_rebate(); return false;"><i class="icon-plus"></i> Add New Rebate</button>
</div>
</div>
</div>
</div>
</br>
<div class="col-lg-2"></div>
<div class="col-md-8">
<div style="overflow:auto" class="well">
</br>
<div class="table-responsive">
<table id="blacklistgrid" class="table table-bordered table-hover table-striped">
<thead>
<tr id="Row1">
<th style="vertical-align:middle">Products</th>
<th style="vertical-align:middle">Pack Of</th>
<th style="vertical-align:middle">Quantity</th>
<th style="vertical-align:middle">Volume</th>
<th style="vertical-align:middle">Unit</th>
<th style="vertical-align:middle">Rebate Amount</th>
</tr>
</thead>
<tbody class="apnd-test">
<tr id="reb1">
<td>
<div class="btn-group">
<select name="product_id" class="form-control prod_list">
<option value="" selected='selected'>Select Product</option>
</select>
</div>
</td>
<td><input type="text" name="pack" id="pack" value="" class="form-control" size="8"/></td>
<td><input type="text" name="quantity" id="quantity" value="" class="form-control" size="8"/></td>
<td><input type="text" name="volume" id="volume" value="" class="form-control" size="8"/></td>
<td>
<div class="btn-group">
<select id="units" name="units" class="form-control">
<option value="" selected='selected'>Select Unit</option>
<option value="5" >Microsecond</option>
<option value="7" >oz</option>
<option value="9" >ml</option>
<option value="10" >L</option>
<option value="12" >gms</option>
</select>
</div>
</td>
<td><input type="text" name="amount" id="amount" value="" class="form-control" size="9"/></td>
</tr>
</tbody>
<tfoot>
<tr id="reb2">
<td><button style="float:right; margin-bottom: 20px" class="btnAdd" type="button" class="btn btn-default" onclick=""> Add</button></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tfoot>
</table>
</div>
</div> <!-- /span8 -->
<div class="row">
<div class="col-xs-6">
<label for="name" class="col-lg-5">Rebate Start Date<span style="color:#FF0000">*</span></label>
<div class="col-lg-6">
<input class="form-control" placeholder="yyyy-mm-dd" type="date" name="rebate_start_date" value="">
</div>
</div>
<div class="col-xs-6">
<label for="name" class="col-lg-6">Rebate Expiry Date<span style="color:#FF0000">*</span></label>
<div class="col-lg-6">
<input class="form-control" placeholder="yyyy-mm-dd" type="date" name="rebate_expiry_date" value="">
</div>
</div>
</div>
</br>
<div class="row">
<div class="col-xs-6">
<label for="name" class="col-lg-5">Applicable States</label>
<div class="col-lg-7">
<select id="example28" multiple="multiple" name="applicable_states[]">
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="4">Arkansas</option>
<option value="5">California</option>
<option value="6">Colorado</option>
<option value="7">Connecticut</option>
<option value="8">Delaware</option>
<option value="9">Florida</option>
<option value="10">Georgia</option>
</select>
</div>
</div>
<div class="col-xs-6">
<label for="name" class="col-lg-6">Rebate Total Count</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="rebate_total_count" id="rebate_total_count" value="">
</div>
</div>
</div>
</br>
<div class="row">
<div class="col-xs-6">
</div>
<div class="col-xs-6">
<label for="name" class="col-lg-6"></label>
<div class="col-lg-6">
<button style="float:right" class="btnAdd" type="button" class="btn btn-default" onclick="add_rebate(); return false;"><i class="icon-plus"></i> Add New Rebate</button>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-5"></div>
<div style="margin-left: -9px" class="col-xs-5">
<button type="submit" class="btn btn-primary">Preview</button>
<button type="button" class="btn btn-default">Go Back</button>
</div>
</div>
</div>
</form>
現在點擊任何「添加新的折扣」按鈕後,下面的塊應該得到追加到第一個塊:
<div style="float: clear;"></div>
<div style="margin-left: 12px" class="col-xs-4">
<div class="form-group">
<label for="company_name" class="col-lg-4">Manufacturer<span style="color:#FF0000">*</span></label>
<div class="col-lg-7">
<select id="company_id" name="company_id" class="form-control" onchange="GetAllProductByManufacturerID(this.value)">
<option value="" selected='selected'>Select Manufacturer</option>
<option value="33" >Eywa Solutions</option>
<option value="37" >Amazon</option>
<option value="40" >Test</option>
<option value="42" >RK</option>
<option value="46" >Santa Margherita</option>
</select>
</div>
</div>
</div>
<div style="margin-left: -61px" class="col-xs-4">
<div class="form-group">
<div class="col-lg-7">
<button style="float:right" class="btnAdd" type="button" class="btn btn-default" onclick="add_rebate(); return false;"><i class="icon-plus"></i> Add New Rebate</button>
</div>
</div>
</div>
</div>
</br>
<div class="col-lg-2"></div>
<div class="col-md-8">
<div style="overflow:auto" class="well">
</br>
<div class="table-responsive">
<table id="blacklistgrid" class="table table-bordered table-hover table-striped">
<thead>
<tr id="Row1">
<th style="vertical-align:middle">Products</th>
<th style="vertical-align:middle">Pack Of</th>
<th style="vertical-align:middle">Quantity</th>
<th style="vertical-align:middle">Volume</th>
<th style="vertical-align:middle">Unit</th>
<th style="vertical-align:middle">Rebate Amount</th>
</tr>
</thead>
<tbody class="apnd-test">
<tr id="reb1">
<td>
<div class="btn-group">
<select name="product_id" class="form-control prod_list">
<option value="" selected='selected'>Select Product</option>
</select>
</div>
</td>
<td><input type="text" name="pack" id="pack" value="" class="form-control" size="8"/></td>
<td><input type="text" name="quantity" id="quantity" value="" class="form-control" size="8"/></td>
<td><input type="text" name="volume" id="volume" value="" class="form-control" size="8"/></td>
<td>
<div class="btn-group">
<select id="units" name="units" class="form-control">
<option value="" selected='selected'>Select Unit</option>
<option value="5" >Microsecond</option>
<option value="7" >oz</option>
<option value="9" >ml</option>
<option value="10" >L</option>
<option value="12" >gms</option>
</select>
</div>
</td>
<td><input type="text" name="amount" id="amount" value="" class="form-control" size="9"/></td>
</tr>
</tbody>
<tfoot>
<tr id="reb2">
<td><button style="float:right; margin-bottom: 20px" class="btnAdd" type="button" class="btn btn-default" onclick=""> Add</button></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tfoot>
</table>
</div>
</div> <!-- /span8 -->
<div class="row">
<div class="col-xs-6">
<label for="name" class="col-lg-5">Rebate Start Date<span style="color:#FF0000">*</span></label>
<div class="col-lg-6">
<input class="form-control" placeholder="yyyy-mm-dd" type="date" name="rebate_start_date" value="">
</div>
</div>
<div class="col-xs-6">
<label for="name" class="col-lg-6">Rebate Expiry Date<span style="color:#FF0000">*</span></label>
<div class="col-lg-6">
<input class="form-control" placeholder="yyyy-mm-dd" type="date" name="rebate_expiry_date" value="">
</div>
</div>
</div>
</br>
<div class="row">
<div class="col-xs-6">
<label for="name" class="col-lg-5">Applicable States</label>
<div class="col-lg-7">
<select id="example28" multiple="multiple" name="applicable_states[]">
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="4">Arkansas</option>
<option value="5">California</option>
<option value="6">Colorado</option>
<option value="7">Connecticut</option>
<option value="8">Delaware</option>
<option value="9">Florida</option>
<option value="10">Georgia</option>
</select>
</div>
</div>
<div class="col-xs-6">
<label for="name" class="col-lg-6">Rebate Total Count</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="rebate_total_count" id="rebate_total_count" value="">
</div>
</div>
</div>
</br>
<div class="row">
<div class="col-xs-6">
</div>
<div class="col-xs-6">
<label for="name" class="col-lg-6"></label>
<div class="col-lg-6">
<button style="float:right" class="btnAdd" type="button" class="btn btn-default" onclick="add_rebate(); return false;"><i class="icon-plus"></i> Add New Rebate</button>
</div>
</div>
</div>
如何實現這使用jQuery。如果用戶希望刪除塊,那麼每個新添加的塊都應該有刪除按鈕。以下是我的原始HTML塊的jsFiddle鏈接。
在您尋求幫助之前,請至少嘗試解決問題 – Populus
@arjan:我已經添加了jsFiddle鏈接。 – PHPLover