gpt4 book ai didi

javascript - 动态创建删除按钮

转载 作者:行者123 更新时间:2023-11-29 17:53:14 25 4
gpt4 key购买 nike

<分区>

每当单击“createaction”按钮时,我都会动态地尝试创建一个包含内容和删除按钮的 div。

每当单击删除按钮时,我都有一个 onclick 函数。但是我这里的代码不起作用,我认为这是因为删除按钮 id 相同。

我怎样才能让这些按钮彼此独一无二?

$("#createAction").click(function() {
var targetDate = $("#targetDate").val();
var newAction = "<div id='actionsDiv'>
<div>
<button type='button' id='delete'> delete</button>
</div>
<label>Target Date:</label>" + targetDate + "
</div>";
$("#actionPlanInfo").append(newAction);

$("#targetDate").val('');

$("#delete").on("click", function() {
var confirmation = confirm('Are you sure you want to delete this action plan/s?');
if (confirmation == true) {
$(this).parent().parent().remove();
}
});
});

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com