我想在單擊加號時添加新的div,並在單擊十字符號時將其刪除。這是一個示例圖像的link。 在加號上,我想添加新的行像交叉符號(在行中包括顏色,大小和數量像1和交叉標誌刪除)。 這是我的HTML。用數據添加新的div並在點擊時將它們刪除
<div class="row select_cart">
<div class="col-md-12">
<div class="col-sm-4">
<div class="new_select">
<select class="form-control" id="attribute137" name="super_attr[137]">
<option>COLOR</option>
<option>Lime Black</option>
<option>Orange Black</option>
</select>
</div>
</div>
<div class="col-sm-4">
<div class="new_select">
<select class="form-control">
<option>7</option>
<option>8</option>
<option>9</option>
</select>
</div>
</div>
<div class="col-sm-3 col-xs-10">
<div class="new_select ">
<select class="form-control">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</div>
</div>
<div class="col-sm-1 col-xs-2">
<a class="button delete" title="add unlimited selections"> <img src="images/item_add.png" alt="" /></a>
</div>
</div>
</div>
我可以用克隆這樣($("div[id^='myrows']").after($('#myrows').clone());)
或複製代碼,反覆使用相同的HTML,但問題是如何安裝特定的叉號,每行和刪除that.I的點擊我的代碼更改點點。
HTML :
<div class="row2">
</div>
JS:
$(".add").click(function(){
var fld = ' <div class="row select_cart2"> <div class="col-md-12"> <div class="col-sm-4"> <div class="new_select"> <select class="form-control"> <option>COLOR</option> <option>Lime Black</option> <option>Orange Black</option> </select> </div> </div> <div class="col-sm-4"> <div class="new_select"> <select class="form-control"> <option>7</option> <option>8</option> <option>9</option> </select> </div> </div> <div class="col-sm-3 col-xs-10"> <div class="new_select "> <select class="form-control"> <option>1</option> <option>2</option> <option>3</option> </select> </div> </div> <div class="col-sm-1 col-xs-2"> <a class="button delete" title="add unlimited selections"> <img src="images/item_add.png" alt=""> </a> </div> </div> </div>';
jQuery('.row2').append(fld);
});
$(".delete").on("click", ".button.delete", function(e){
$(this).closest(".row.select_cart2").remove();
e.preventDefault();
});
大代碼worked.Thanks –