我正在尝试使用带有删除功能的列表元素附加它。我已经创建了 remove 函数,我可以附加元素,但不知道如何使用 remove 函数附加元素。
这是代码
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#btn1").click(function () {
var listname = $('#listname').val();
$(".container").append($('<ol>', {
text: listname
}));
});
$("#btn2").on('click', function () {
var name = $('#name').val();
$('ol').append($('<li>', {
text: name
}));
});
$('ol').on('click', '.btn3', function () {
$(this).parent('li').remove();
});
});
</script>
<title></title>
</head>
<body>
<ol>
<li>List item 1 <button class="btn3">remove</button></li>
<li>List item 2 <button class="btn3">remove</button></li>
<li>List item 3 <button class="btn3">remove</button></li>
</ol>
<form>
<input id="name" type="text"> <button id="btn2">Append list items</button>
</form>
</body>
</html>
提示,评论将不胜感激