这是html:
<button id="btn1">CLICK 1</button>
<button id="btn2">CLICK 2</button>
<div id="show"></div>
这是javascript:
product_id = new Array();
$("#btn").on('click', function () {
$("#show").append("<div><button type='button' id='btn1x' class='close pull-right' aria-hidden='true'>×</button>" + "<pre>button 1</pre></div>");
product_id.push("btn1");
alert(product_id);
});
$(document).on('click', 'button#btn1x', function () {
$(this).parent().remove();
alert(product_id);
//when I click this button, i want to remove the "btn1" that I pushed a while ago from my array
});
$("#btn2").on('click', function () {
$("#show").append("<div><button type='button' id='btn2x' class='close pull-right' aria-hidden='true'>×</button>" + "<pre>button 2</pre></div>");
product_id.push("btn2");
});
$(document).on('click', 'button#btn2x', function () {
$(this).parent().remove();
//when I click this button, i want to remove the "btn2" that I pushed a while ago from my array
});
我想单击按钮,最终将在我创建的数组中插入某个值。但是,我还创建了一个关闭按钮,当我单击它时,我想从数组中删除插入的值。